【问题标题】:Will numpy.save() always convert lists to arrays?numpy.save() 是否总是将列表转换为数组?
【发布时间】:2023-03-22 22:54:01
【问题描述】:

如果我这样做

import numpy as np 
h = [1,2,3]
np.save("h.npy",h)
h = np.load("h.npy")
print(type(h))

结果是

<class 'numpy.ndarray'>

总是这样吗? np.savez() 也一样吗?在online documentation 中,它只是说h 应该是类似数组的。

【问题讨论】:

    标签: python arrays list numpy save


    【解决方案1】:

    是的,会的。

    在内部,numpy.save 在数据上使用np.asanyarray,如在source code for np.savesource code for np.savez 中所示。

    【讨论】:

      猜你喜欢
      • 2017-12-04
      • 2010-11-28
      • 1970-01-01
      • 2014-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      相关资源
      最近更新 更多