TypeError:“list”对象不能解释为整数Python NumPy

2024-06-17 15:40:49 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有办法将字符串列表转换成numpy.ndarray?。因为我尝试了以下代码:

All  = np.ndarray([str(necessary_lines).split(',')])

这就产生了这个错误:

Traceback (most recent call last):
  File "/Users/username/Desktop/Coding/Python/somePythonProgram.py", line 47, in <module>
    print(parseCSV(file))
  File "/Users/username/Desktop/Coding/Python/somePythonProgram.py", line 34, in somePythonProgram
    All  = np.ndarray([str(necessary_lines).split(',')])
TypeError: 'list' object cannot be interpreted as an integer

还是不能将字符串列表转换为numpy数组


Tags: 字符串numpy列表npusernameallusersfile