我如何在pyhton numpy阵列中输入空间分离整数。 (例如列表(Map(int,input()。spli(; quot; quot; quot;))函数适用于列表。)
我试图找到替代方案,但仅适用于列表,而不是用于numpy阵列,
但我尝试过的是:
5
1 2 3 4 5
Traceback (most recent call last):
File "<string>", line 6, in <module>
File "/usr/local/lib/python3.8/dist-packages/numpy/core/numeric.py", line 204, in ones
a = empty(shape, dtype, order)
TypeError: expected sequence object with len >= 0 or a single integer
我需要一个版本的list(map(int,input()。split()。split(“”))
>对于Numpy数组。
I have tried to find alternatives but only available for list not for numpy arrays
I tried this but didnt work:
5
1 2 3 4 5
Traceback (most recent call last):
File "<string>", line 6, in <module>
File "/usr/local/lib/python3.8/dist-packages/numpy/core/numeric.py", line 204, in ones
a = empty(shape, dtype, order)
TypeError: expected sequence object with len >= 0 or a single integer
I need a version of list(map(int,input().split(" "))
for numpy arrays.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需转换为numpy数组:
输出:
You can just convert to a numpy array:
Output: