【问题标题】:Assigning "list of directory" array on numpy在 numpy 上分配“目录列表”数组
【发布时间】:2019-07-03 22:40:56
【问题描述】:

我尝试在 numpy 数组上分配目录列表,但不知何故,该数组只存储第一个字母,而不是字符串的完整地址。

lasdir=np.array(range(4), dtype=str).reshape(2,2)
i=0
for root, dirs, files in os.walk(source_dir):
    for file in files:
        if (file.lower().endswith(".las")):
            lasdir[i,0]=file
            lasdir[i,1]=os.path.join(root, file)
            i=i+1

有人知道为什么吗?

【问题讨论】:

    标签: python numpy


    【解决方案1】:

    当使用str dtype 时,它​​使用固定长度的字符串。正如 in this answer 建议的那样,你最好使用 dtype object

    所以你的第一行可以转换为:

    lasdir = np.empty((2,2), dtype=object)
    

    【讨论】:

      猜你喜欢
      • 2018-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-09
      • 2017-12-23
      • 2016-08-04
      • 2019-03-02
      相关资源
      最近更新 更多