【发布时间】:2021-12-12 07:50:15
【问题描述】:
当我将字符串分配给数组时,它只会拾取第一个字符,我需要整个字符串。我是不是用错了方法?
import numpy
i=0
def func(name,number,array,i):
arry[i,0]=number
array[i,1]=name
print(array)
People= numpy.zeros([5,2],dtype=str)
func("qwe","123",People,i)
#this is the output
[['1' 'q']
['' '']
['' '']
['' '']
['' '']]
#this is the desired output
[['123' 'qwe']
['' '']
['' '']
['' '']
['' '']]
【问题讨论】:
-
String dtype 具有特定的大小。使用
dtype='U10' or something like that. Look at thePeople.dtype`。
标签: arrays numpy variable-assignment