Changing dtype of single column in 2d numpy array

I create a 2d array full of zeros with the following line of code:

MyNewArray=zeros([4,12],float)

However, the first column will need to be filled with text data in the form of rows, and all other columns will need to be filled with numerical data that can be mathematically manipulated.

How can I change the code above so that the first column in the matrix can be a row data type, saving all other columns as a float?

+5
source share
1 answer

You might want to use structured arrays.

MyNewArray = zeros(12, dtype='S10,f4,f4,f4')

, 4 : 10 ( float f4). , . .

, f0-f3 . , ():

MyNewArray['f0']

, .

+5

All Articles