1

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?

1
  • Well the dtype is i8 and NaN cannot be represented by int dtype so it looks like all that happens is it's being set to some unitialised value Commented Jun 10, 2016 at 15:10

1 Answer 1

3

The second column can't be nan. It has an integer type. There is no nan representation for integers.

The value -9223372036854775808 is -2**63, i.e. the most negative 64 bit signed integer.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.