+ 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?

3rd Jul 2018, 4:17 PM
Maninder $ingh
Maninder $ingh - avatar
9 Antworten
+ 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 👍
3rd Jul 2018, 7:28 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 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
4th Jul 2018, 8:36 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 12
Maninder Singh Haha... 😂 Thanks, man. But it was Qwertiony who answered first, so... ;)
4th Jul 2018, 5:50 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 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
3rd Jul 2018, 4:32 PM
Qwertiony
Qwertiony - avatar
+ 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.
4th Jul 2018, 1:10 AM
Maninder $ingh
Maninder $ingh - avatar
+ 6
Kuba Siekierzyński what impressed me the most is your vocabulary. I had to lookup 'capacious'!
4th Jul 2018, 7:35 AM
Louis
Louis - avatar
+ 3
Qwertiony can give me code please i got error it's very important for me please.
3rd Jul 2018, 4:38 PM
Maninder $ingh
Maninder $ingh - avatar
+ 2
3rd Jul 2018, 4:43 PM
Qwertiony
Qwertiony - avatar
+ 2
Qwertiony Thanks.
4th Jul 2018, 1:10 AM
Maninder $ingh
Maninder $ingh - avatar