I would like to take the information from some fields and just write them into another variable using a list.
import numpy as np
var1 = np.array([(1,2,3,4),(11,22,33,44),(111,222,333,444)], dtype=([('field1', 'int32'),('field2','int32'),('field3','int32'),('field4','int32')]))
var2 = np.empty((1), dtype = ([('field1', 'int32'),('field2','int32'),('field5','int32'),('field6','int32')]))
myList = ['field1', 'field2']
I want to write the values from the 1st and 2nd fields and 1st row to var2. I try the following:
var2[(myList)] = var1[(myList)][0]
But I get the following error:
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
What I want to achieve the same if I perform:
var2['field1'] = var1['field1'][0]
var2['field2'] = var1['field2'][0]
How could I do this in order to able to perform this with higher lists avoiding a for loop over the list?