Regarding storing different data types in numpy arrays

can we store different type of data in a single numpy array

like storing string in 1 column and storing integers in another column or same data type should be there for whole numpy array??

Hey @amankharb, yes you are right, we can store different types of data in a single numpy array. It is possible to store string in 1 column and store integers in another column.

Hope this helps !
Happy Learning :slight_smile:

i want to ask that if i have a numpy array of all integer values of shape m*n and then i want to change one of the columns datatype to string can we do that?? if yes how??

as i am trying to do that but it is throwing an error

No first you asked something else. If this is your case then you cannot change one of the columns datatype. But to achieve the same I would say that first store all your mixed data as a list and then convert that list into a numpy array. Something like this :

import numpy as np 
l=[['a',20,30],['a',20,"abc"],["abc",3,"aman"]]
m = np.array((l))
print(m)

Hope this helps.
Happy Learning :slight_smile:

ok now i got it thankx bhaiya

1 Like