I'm getting a run-time error when trying to append field(s) to a structured array of size ONE. I've written a simple example below:
import numpy as np
import numpy.lib.recfunctions as rcfuncs
dtype_ = np.dtype( { 'names': ["field_a","field_b","field_c"]
, 'formats': ['S32', 'i4', 'f8']}
)
data_ = [("1",17, 123.45)]
numpy_array = np.array(data_, dtype_)
# append 2 fields
numpy_array = rcfuncs.append_fields( numpy_array,["field_d","field_e"],data=[ "1","3" ] )
# append 1 field fails :(
numpy_array = rcfuncs.append_fields( numpy_array, "field_f", data=["123456"] )
I'm getting the error:
TypeError: descriptor 'ravel' requires a 'numpy.ndarray' object but received a 'numpy.void'
As well, if I 'invert' the appends, the statement with the two fields append will fail:
# append 1 field
numpy_array = rcfuncs.append_fields( numpy_array, "field_f", data=["123456"] )
# append 2 fields fails :(
numpy_array = rcfuncs.append_fields( numpy_array,["field_d","field_e"],data=[ "1", "3" ] )
I am running with python 2.7.11 and numpy 1.11.0 and I do not have the issue when the initial array is of size greater than 2.
How to solve the type error?
Thanks
We do not get the TypeError when setting the optional parameter usemask to False
numpy_array = \
rcfuncs.append_fields(numpy_array, "field_f", data=["123456"], usemask=False)
numpy_array = \
rcfuncs.append_fields(numpy_array,["field_d","field_e"],data=[ "1", "3" ], usemask=False)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With