0

If I define a structured array:

import numpy as np
x = np.array([(1, 'O', 1)],
             dtype=np.dtype([('step', 'int32'),
                             ('symbol', '|S1'),
                             ('index', 'int32')]))

seems fine until I do this:

import numpy.lib.recfunctions as rec
rec.append_fields(x,'x',x['index']+1)

gives me

TypeError: object of type 'numpy.int32' has no len()

presumably because x.shape is (1,) rather than (1,3). How do I append columns to this structured array?

4
  • Strange, for me this works fine as expected (numpy 1.5). Commented Oct 12, 2011 at 12:54
  • Your code works for me. What version of Python/NumPy are you using? Commented Oct 12, 2011 at 12:54
  • This is a bug in older versions of numpy (such as 1.3.0). It seems to only affect structure arrays of shape (1,). Commented Oct 12, 2011 at 13:27
  • I am working with version 1.4 on OSX... Commented Oct 12, 2011 at 14:29

1 Answer 1

1

Thanks all. On NumPy 1.4.1 this was giving me the error but I just upgraded to the git 2.0 version and it works fine.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.