我尝试使用另一个矩阵实例化coo_matrix
。当我尝试打印(1, 9) 1.0
(1, 10) 1.0
(1, 11) 1.0
(1, 25) 1.0
(1, 47) 1.0
(2, 1) 1.0
(2, 7) 1.0
(2, 11) 3.0
(2, 12) 1.0
(2, 13) 1.0
(2, 15) 2.0
(2, 19) 1.0
(2, 42) 1.0
(3, 0) 1.0
(4, 20) 1.0
(4, 22) 1.0
(4, 24) 1.0
: :
(45, 0) 1.0
(45, 7) 1.0
(45, 14) 2.0
(45, 20) 1.0
(45, 26) 1.0
(45, 38) 1.0
(45, 40) 1.0
(46, 11) 1.0
(46, 19) 1.0
(46, 36) 1.0
(46, 41) 1.0
(46, 47) 1.0
时,输出为:
coo_matrix
如何打印完整的set_printoptions(threshold = 'nan')
?我尝试使用import java.util.*;
class bday {
public static void main(String[] args){
Scanner yearfinder = new Scanner(System.in);
System.out.println("Please type any year");
int year = yearfinder.nextInt();
Scanner monthfinder = new Scanner(System.in);
System.out.println("Please type any month");
String textmonth = monthfinder.nextLine();
int month;
switch(textmonth) {
case ("january"):
month = 1;
break;
case ("february"):
month = 2;
break;
case ("march"):
month = 3;
break;
case ("april"):
month = 4;
break;
case ("may"):
month = 5;
break;
case ("june"):
month = 6;
break;
case ("july"):
month = 7;
break;
case ("august"):
month = 8;
break;
case ("september"):
month = 9;
break;
case ("october"):
month = 10;
break;
case ("november"):
month = 11;
break;
case ("december"):
month = 12;
break;
default:
System.out.println("The month you input was invalid");
}
Scanner datefinder = new Scanner(System.in);
System.out.println("Please type any day");
int date = datefinder.nextInt();
System.out.println("The date you gave was " + date + "/" + month + "/" + year);
}
}
//Jan 1 1900 was a monday.
,但它并没有解决这个问题。
答案 0 :(得分:1)
您可以使用.todense()
方法将稀疏矩阵转换为密集矩阵:
print(my_coo_matrix.todense())
编辑:您的问题听起来也像是要打印零值元素,但是如果您只想打印非零元素,则可以手动迭代矩阵:
for row, col, value in zip(my_coo_matrix.row, my_coo_matrix.col, my_coo_matrix.data):
print "({0}, {1}) {2}".format(row, col, value)
答案 1 :(得分:0)
我发现使用spy()直观地表示它很有帮助。
spy(coo_matrix)
答案 2 :(得分:0)
(对于非常大的 coo_matrix)导出到 csv
,然后将其保存为 xlsx
可能会有所帮助。
示例:
import numpy
numpy.savetxt('coo_matrix.csv', coo_matrix.todense(), delimiter = ',')