Very simple question: I have a structured array with multiple columns and I'd like to fill only some of them (but more than one) with another preexisting array.
This is what I'm trying:
strc = np.zeros(4, dtype=[('x', int), ('y', int), ('z', int)])
x = np.array([2, 3])
strc[['x', 'y']][0] = x
This gives me this future warning:
main:1: FutureWarning: Numpy has detected that you (may be) writing to an array returned by numpy.diagonal or by selecting multiple fields in a recordarray. This code will likely break in a future numpy release --see numpy.diagonal or arrays.indexing reference docs for details.The quick fix is to make an explicit copy (e.g., doarr.diagonal().copy() or arr[['f0','f1']].copy()).
But even though this is a warning, the structured array doesn't get filled. So far I'm iterating over both arrays and it works but I guess that's highly inefficient. Is there a better way?