1

I have constructed a NumPy array and filled it with data:

data = np.zeros(ndata,dtype=[('datetime',np.dtype(np.datetime64)),\
    ('Value','<f8'),('Weight','<f8')])

However, now I want to do things like returning just the datetime 'column' or just the values. But this isn't a 2D NumPy array. This is a 1D array of some custom dtype, so I can't do for example:

data[:,0]

I assume this is trivial or I've fundamentally got the wrong idea about how to use NumPy arrays.

1 Answer 1

2

A numpy datatype can be accessed just like a dictionary, so you can just do:

data[0]['datetime']

To get the datetime field of row zero or

data[:]['datetime']

To get an array of the datetime field for all rows.

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

2 Comments

Oh great, I was hoping the answer was something as trivial as this. Thanks.
No problem! Often in python you can just try the easiest thing you can think of and it will work :)

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.