import numpy as np
arr = np.array([(1,2), (3,4)], dtype=[('c1', float), ('c2', float)])
arr += 3
results in an invalid type promotion error. Is there a way I can have nice labeled columns like a structured array, but still be able to do operations like it's a simple dtype=float array?
Alternatively, is there an easy way to cast a dtype=float array into a structured array? i.e.
arr = np.array([(1,2), (3,4)], dtype=float)
arr_struc = arr.astype([('c1', float), ('c2', float)])
only where it doesn't broadcast and matches columns to names. Seems like I shouldn't have to do this loop:
arr_struc = np.zeros(2, dtype=[('c1', float), ('c2', float)])
for i,key in enumerate(arr_struc.dtype.names): arr_struc[key] = arr[i,:]
numpy.lib.recfunctionsmodule. In has astructured_to_unstructuredandunstructured_to_structuredfunctions. Aviewif it works is faster, but these are more general purpose..viewagain, see my edit