+ 5
How to use string data in numpy Python?
I create a numpy array which has float values in it.but when I assign a string data type value to array it give me error. import numpy as np x=np.ones((3,3)) x[0][0]='M' print(x) #i got error due to assign a string data type value can you tell me how i can do that?
9 ответов
+ 17
Well, much like Qwertiony said:
https://code.sololearn.com/cWjC30xs7wRV/?ref=app
numpy.array can only be of one type, so you have to choose the most capacious one 👍
+ 13
Louis Actually, I wasn't sure if the word existed ;) English is so cool, you can take a guess in hope everyone will understand you and more often that not it turns out to be correct :D
+ 12
Maninder Singh Haha... 😂 Thanks, man. But it was Qwertiony who answered first, so... ;)
+ 7
You cant mix up types in default ndarray. To do this you need to specify an object type. arr =np.array(..., dtype=object).
might work with ones np.ones(..., dtype=object), not sure though
+ 6
Kuba Siekierzyński when I have a problem and I can't able to solve it then I know there is a person he is a god of python.thank you very much.
+ 6
Kuba Siekierzyński what impressed me the most is your vocabulary. I had to lookup 'capacious'!
+ 3
Qwertiony can give me code please i got error it's very important for me please.
+ 2
Maninder Singh drop it
+ 2
Qwertiony Thanks.