上代码:
from scipy import sparse as sp
import numpy as np
row = np.array([0,0,1,3,1])
col_1 = np.array([0,2,1,2,3])
col_2 = np.array([0,2,1,2,1])
data = np.array([1,2,3,4,5])
'''if two same values are at the same position,there will be no errors'''
print 'col_1:\n',sp.coo_matrix((data,(row,col_1)),shape=(5,5)).todense()
print 'col_2:\n',sp.coo_matrix((data,(row,col_2)),shape=(5,5)).todense()
A_1 = sp.coo_matrix([[1,2],[3,4]])
A_2 = sp.coo_matrix([1,2],[3,4])
'''leaving a bracket for A_2'''
print 'A_1:\n',A_1.todense()
print 'A_2:\n',A_2.todense()
description:
1.使用coo_matrix的时候,存在传入参数同一个位置两个不同值的问题,这个时候对应位置是两个值的和,然而并没有warning和error提示!是不是很危险?
2.对于A_1,“([ [1,2],[3,4] ])”,对于A_2,“([1,2],[3,4])”,没有warning.