2017-06-01 78 views
6

我想打印一個無截斷的numpy數組。我看到了其他解決方案,但這些解決方案似乎並不奏效。打印無省略號的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) 
+1

它爲我,也許你total_list不是numpy的陣列? – Psidom

+1

這不是如何numpy數組看起來。你確定它不是熊貓系列? – ayhan

+0

你想打印到文件? – Aaron

回答

5

使用下面的代碼片段得到省略號。

import numpy 
numpy.set_printoptions(threshold=numpy.nan) 

numpy.set_printoptions(threshold='nan') 

編輯:

如果你有一個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()方法來獲得所需的結果。

+0

我試過了。沒有工作 – Harjatin

+0

python和numpy版本? –

+0

Python 3.5.2,numpy 1.11.1 – Harjatin

3

您可以通過它更改爲list繞過怪異numpy的再版/打印行爲:

print list(total_list) 

應打印出你2元NP陣列的列表。

+0

這仍然給出相同的輸出 – Harjatin

+1

古怪 - 如果使用'total_list.tolist()',它會發生嗎? –

+1

你可能會運行一個不同的代碼你編輯:))我可以確認這兩個答案工作正常。添加一個'print(「hello」)'或其他什麼 –

3

你是不是打印numpy陣列。

添加以下行進口後:

pd.set_option('display.max_rows', 100000) 
+0

謝謝。這工作。我有點困惑,不應該'total_list = np.array(total_list)'隱藏DataFrame到numpy數組嗎? – Harjatin