我看过其他示例(例如Getting a map() to return a list in Python 3.x这样的示例),但我无法弄清楚。我正在尝试打开一个这样的列表(大约一千行,但在这里我简写为它)
xyz = [' 0.35587716 -2.11974747 -3.69604539',
' 0.32428861 -2.15566737 -3.61313426',
' 0.35329223 -2.19372613 -3.75673156']
放入这样的数组或浮点列表
b = [[0.35587716, -2.11974747, -3.69604539],
[0.32428861, -2.15566737, -3.61313426],
[0.35329223, -2.19372613, -3.75673156]]
我尝试了以下
b = np.array(map(lambda x: map(int, x.split()), xyz))
b = [[int(y) for y in x.split()] for x in xyz]
with open("file.log") as f:
lis=[map(int,line.split()) for line in f]
所有这些都给了我类似的东西:
<map object at 0x117a89390>
<map object at 0x117a89390>
<map object at 0x117a89390>
等,等等。
但是我不知道如何访问map对象中的值。我正在使用Python 3.6.0。我不确定该怎么办:(