I have a numpy array with a nested dtype:
dt = np.dtype([('e', '<f8'), ('n', '<i8'), ('pos', '<f8', (3,))])
arr = np.zeros(5, dtype=dt)
array([(0.0, 0, [0.0, 0.0, 0.0]), (0.0, 0, [0.0, 0.0, 0.0]),
(0.0, 0, [0.0, 0.0, 0.0]), (0.0, 0, [0.0, 0.0, 0.0]),
(0.0, 0, [0.0, 0.0, 0.0])],
dtype=[('e', '<f8'), ('n', '<i8'), ('pos', '<f8', (3,))])
and I'm trying to fill the entire array with np.nan:
arr[:] = np.nan
However, this does not work as expected:
array([(nan, -9223372036854775808, [nan, nan, nan]),
(nan, -9223372036854775808, [nan, nan, nan]),
(nan, -9223372036854775808, [nan, nan, nan]),
(nan, -9223372036854775808, [nan, nan, nan]),
(nan, -9223372036854775808, [nan, nan, nan])],
dtype=[('e', '<f8'), ('n', '<i8'), ('pos', '<f8', (3,))])
The second column here is obviously not nan.
Any idea how I can work around this issue?
dtypeisi8andNaNcannot be represented byintdtypeso it looks like all that happens is it's being set to some unitialised value