【发布时间】:2017-12-24 21:11:51
【问题描述】:
当尝试将 numpy 矩阵 M 写入二进制文件时:
from io import open
X = [random.randint(0, 2 ** self.stages - 1)for _ in range(num)]
Matrix = np.asarray([list(map(int, list(x))) for x in X])
file_output = open('result.bin', 'wb')
M = np.ndarray(Matrix, dtype=np.float64)
file_output.write(M)
file_output.close()
我收到此错误:
Traceback (most recent call last):
File "experiments.py", line 164, in <module>
write_data(X, y)
File "experiments.py", line 39, in write_data
arr = np.ndarray(Matrix, dtype=np.float64)
ValueError: sequence too large; cannot be greater than 32
我能知道如何解决这个问题吗?谢谢
【问题讨论】:
-
请先修复您的代码(例如文件名)。
-
您忘记打开一个字符串。请先解决这个问题。
-
哦!谢谢你 。但还是有同样的问题
-
arr = np.ndarray(Matrix, dtype=np.float64)出现错误。我们需要知道Matrix是什么。请创建一个minimal, complete and verifiable example。 -
看来问题在于使用
np.ndarray。 this问题的答案建议不要使用它,而是使用np.array