> -6ren">
gpt4 book ai didi

python - Numpy savetxt 类型错误

转载 作者:太空宇宙 更新时间:2023-11-03 16:43:52 24 4
gpt4 key购买 nike

我正在尝试保存 5D 数组,但遇到此错误。

> Traceback (most recent call last):   File "model_3.py", line 53, in
> <module>
> np.savetxt('../test_set/exp3/X.txt', X_test, delimiter=' ', fmt='%1.12f') File
> "/home/jasper/.virtualenvs/thesis/local/lib/python2.7/site-packages/numpy/lib/npyio.py",
> line 1160, in savetxt
> % (str(X.dtype), format)) TypeError: Mismatch between array dtype ('float64') and format specifier ('%1.12f %1.12f %1.12f')

最佳答案

savetxt 迭代数组的第一维,并为每个“行”尝试执行以下操作:

format % tuple(row)

根据 fmt 和数组形状 (X.shape[1]) 构造的格式

'%1.12f %1.12f %1.12f'

如果数组不是 2d,则 row 将不是 1d,并且此 tuple(row) 转换将与 format 不匹配。

savetxt 是为简单的 2d 数组(或 1d 结构化数组)设计的,而不是 5d 数组。

关于python - Numpy savetxt 类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36525713/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com