从excelsheet中,我导入了各种列,我写道:
import numpy as np
totaloutput = []
inputdata = np.stack(various columns)
for "number of variables in columns" in inputdata:
calculate several numpy.ndarray-type arrays
output = np.column_stack(several numpy.ndarray-type arrays)
totaloutput.append(output)
当我打印totaloutput
时,我得到:
[array([['0.8', '4.0', '0.5', '5.0', 'X','Y', '16.0',
'345.0', '285.0', '0.5843940254127079', '0.3583943421752271'],
['0.8', '4.0', '0.5', '5.0', 'X','Y', '17.0',
'345.0', '285.0', '0.36329780170652354', '0.22314099222162737'],
[etc],
[etc]],dtype='<U32'), array([['1.2', '4.0', '0.5', '5.0', 'X', 'Y',
'16.0',
'345.0', '15.0', '0.787996644827825', '0.48299132454894594'],
[etc],
[etc]],dtype='<U32'),
根据type(totaloutput)
的输出类型是list
。但是,为了能够导出数据,我必须设法获得以下形状的数据:
[['0.800000011920929' '3.5' '1.0' '4.0' 'X', 'Y', '15.0'
'345.0' '285.0' '0.6222837267695641' '0.37663730483688007']
['0.800000011920929' '3.5' '1.0' '4.0' 'X', 'Y', '15.0'
'345.0' '285.0' '1.4079677072051757' '0.8500865690052523'][etc][etc]]
我以为我解决了这个问题:
totaloutput = np.asarray(totaloutput)
totaloutput = np.reshape((totaloutput, ((len(inputdata)),11))
每当我延长inputdata
的数量(这是脚本的目标,自动计算大量数据)时,np.asarray
似乎不再起作用。我发现有人problems with this了。
我可以通过在totaloutput
之前打印np.asarray(totaloutput)
来确认这一点,然后说明两个打印件是相同的。 (不受欢迎的数组= ... dtype事物)奇怪的是,在np.asarray(totaloutput)
之后我打印type
时,它会说numpy.ndarray
inputdata
后np.asarray(totaloutput)
较小,会产生一个整齐的numpy.ndarray
输出。
我已经尝试了很多其他方法来获得正确的输出,我已经看到了
for i in range(len(inputdata)):
print(totaloutput.item(i))
正是我需要的,但无论何时我尝试:
for i in range(len(inputdata)):
finaloutput = (totaloutput.item(i))
我得到了
totaloutput =(totaloutput.item(i))
AttributeError:'str'对象有 没有属性'item'