我想打印一个不带截断的numpy数组。我已经看到了其他解决方案,但这些似乎都不起作用。
以下是代码片段:
total_list = np.array(total_list)
np.set_printoptions(threshold=np.inf)
print(total_list)
下面是输出的样子:
22 A
23 G
24 C
25 T
26 A
27 A
28 A
29 G
..
232272 G
232273 T
232274 G
232275 C
232276 T
232277 C
232278 G
232279 T
这是完整的代码。我可能在类型转换中犯了一个错误。
import csv
import pandas as pd
import numpy as np
seqs = pd.read_csv('BAP_GBS_BTXv2_imp801.hmp.csv')
plts = pd.read_csv('BAP16_PlotPlan.csv')
required_rows = np.array([7,11,14,19,22,31,35,47,50,55,58,63,66,72,74,79,82,87,90,93,99])
total_list = []
for i in range(len(required_rows)):
curr_row = required_rows[i];
print(curr_row)
for j in range(len(plts.RW)):
if(curr_row == plts.RW[j]):
curr_plt = plts.PI[j]
curr_range = plts.RA1[j]
curr_plt = curr_plt.replace("_", "").lower()
if curr_plt in seqs.columns:
new_item = [curr_row,curr_range,seqs[curr_plt]]
total_list.append(new_item)
print(seqs[curr_plt])
total_list = np.array(total_list)
'''
np.savetxt("foo.csv", total_list[:,2], delimiter=',',fmt='%s')
total_list[:,2].tofile('seqs.csv',sep=',',format='%s')
'''
np.set_printoptions(threshold='nan')
print(total_list)
发布于 2017-06-01 23:35:09
使用下面的代码片段可以不使用省略号。
import numpy
import sys
numpy.set_printoptions(threshold=sys.maxsize)
编辑:
如果您有pandas.DataFrame
,请使用以下代码片段来打印您的数组:
def print_full(x):
pd.set_option('display.max_rows', len(x))
print(x)
pd.reset_option('display.max_rows')
或者,您可以使用pandas.DataFrame.to_string()方法来获得所需的结果。
编辑‘:
这篇文章的一个早期版本建议了下面的选项
numpy.set_printoptions(threshold='nan')
从技术上讲,这可能是可行的,然而,numpy文档将int和None指定为允许的类型。参考:https://docs.scipy.org/doc/numpy/reference/generated/numpy.set_printoptions.html。
发布于 2017-06-01 23:39:07
您可以通过将其更改为list
来绕过奇怪的Numpy repr/print行为:
print list(total_list)
应该打印出2元素np数组的列表。
发布于 2017-06-02 00:21:58
你是而不是打印numpy数组。
在导入后添加以下行:
pd.set_option('display.max_rows', 100000)
https://stackoverflow.com/questions/44311664
复制相似问题