當我將字串分配給陣列時,它只會選取第一個字符,而我需要整個字串。我使用了錯誤的方法嗎?
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']
['' '']
['' '']
['' '']
['' '']]
uj5u.com熱心網友回復:
分配 people 陣列來保存物件而不是字串:
People= numpy.zeros([5,2], dtype=object)
print(func("qwe","123",People,i))
# [['123' 'qwe']
# ['' '']
# ['' '']
# ['' '']
# ['' '']]
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/338367.html
下一篇:位移時保留標量資料型別
