![](https://secure.gravatar.com/avatar/fda7e3244f26d8f72140f6f16b5fc93d.jpg?s=120&d=mm&r=g)
Hi, I am really confused on the np array or record array, and cannot understand how it works. What I want to do is that I have a normal python two dimensional array/list: a = [['2000-01-01', 2],['2000-01-02', 3]] I want to convert it to a recarray with this dtype [('date', 'object'), ('count', 'int')]. I tried multiple ways and none of them works. And some of the tests show pretty odd behavior. This is good, and it is almost what i want:
import numpy as np a = [('2000-01-01', 2), ('2000-01-02', 3)] np.array(a, dtype=[('date', 'object'), ('count', 'int')]) array([('2000-01-01', 2), ('2000-01-02', 3)], dtype=[('date', '|O8'), ('count', '<i8')])
Why this doesn't work?!
a = [['2000-01-01', 2],['2000-01-02', 3]] np.array(a, dtype=[('date', 'object'), ('count', 'int')]) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: tried to set void-array with object members using buffer.
Why can this cause segmentation fault?!
a = [['2000-01-01', 2],['2000-01-02', 3]] np.ndarray((len(a),), buffer=np.array(a), dtype=[('date', 'object'), ('count', 'int')]) Segmentation fault (And python quit!)
Python version 2.6.5 On this reference page, http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html
x = np.array([(1,2),(3,4)]) x array([[1, 2], [3, 4]]) np.array([[1, 2], [3, 4]]) array([[1, 2], [3, 4]])
Can anyone help me about this? Thanks.