我正在尝试使用一些字符串制作2d浮点数组。我将其分解为分别制作2个数组,然后尝试将它们组合成2d数组,但实际字面是“ array”。当我使用底部列出的较小阵列时,该问题无法复制。
如果我像np.array([...] [...])那样做,那么我会得到[list(...),list(...)]
我的代码
a = np.array([75.145, 70.082, '-', 65.537, 76.230, 68.224, 69.841, 75.962, 72.963, 84.492, 73.016, 78.571, 75.314, 76.812, 68.504, 73.004])
b = np.array(['-', 70.124, 67.873, 67.630, 76.230, 81.250, 66.990, 66.559, 66.860, 80.749, 69.780, 77.249, 84.058, 79.592, 78.261, 72.174, 73.507])
c = [a, b]
d = np.array(c)
print(d)
输出
[array(['75.145', '70.082', '-', '65.537', '76.23', '68.224', '69.841',
'75.962', '72.963', '84.492', '73.016', '78.571', '75.314',
'76.812', '68.504', '73.004'], dtype='<U32')
array(['-', '70.124', '67.873', '67.63', '76.23', '81.25', '66.99',
'66.559', '66.86', '80.749', '69.78', '77.249', '84.058', '79.592',
'78.261', '72.174', '73.507'], dtype='<U6')] #Somehow there's not even a closing ] here
所需的输出
[['75.145' '70.082' '-' '65.537' '76.23' '68.224' '69.841' '75.962', '72.963' '84.492' '73.016' '78.571' '75.314' '76.812' '68.504' '73.004'],
['-','70 .124','67 .873','67 .63','76 .23','81 .25','66 .99','66 .559','66 .86','80 .749','69 .78','77 .249 ','84 .058','79 .592','78 .261','72 .174','73 .507']]
无法复制问题的较小阵列。
a = np.array([75.145, 70.082, '-'])
b = np.array(['-', 70.124, 67.873])
c = [a, b]
d = np.array(c)
print(d)
[['75.145' '70.082' '-']
['-' '70.124' '67.873']]
答案 0 :(得分:0)
您可以尝试:
import numpy as np
a = np.array([1,2,3,4,'-',4])
a.tolist()