我有一个总值为的文件4950:
0.012345678912345678
Run Code Online (Sandbox Code Playgroud)
我使用以下方式读取文件:
a = numpy.genfromtxt(file_name, dtype=str, delimiter=',') # a.shape = (4950L, 1L) #dtype=str as I don't want to compromise accuracy
#say a == ['0.000000000000000001', -'0.000000000000000002', ...., '0.000000000004950']
Run Code Online (Sandbox Code Playgroud)
我想要实现的是获得一个b大小(100L, 100L)的矩阵:
示例(准确性很重要):
array = ['1','2','-3','-5','6','-7'] # In reality the data is up to 18 decimal places.
final_matrix = [
['0','1','2','-3'],
['-1',0,'-5','6'],
['-2','5','0','-7'],
['3','-6','7','0']
]
Run Code Online (Sandbox Code Playgroud)
实现这一目标的最有效方法是什么?