the tuple (row) is one element of the structured array. It's possible

to have an n-dimensional structured array where each element is a

tuple.

Also just was looking at this and while you can't do this

anarray = np.array([1,2,3], dtype = [('num', int)])

you can

anarray = np.array([(1,),(2,),(3,)], dtype = [('num', int)])

Vincent

On Sat, May 15, 2010 at 7:37 AM, <josef.pktd@gmail.com> wrote:

the tuple (row) is one element of the structured array. It's possibleOn Sat, May 15, 2010 at 9:27 AM, Jimmie Houchin <jlhouchin@gmail.com> wrote:

> On 5/15/2010 6:30 AM, josef.pktd@gmail.com wrote:

>> On Sat, May 15, 2010 at 12:24 AM, Jimmie Houchin<jlhouchin@gmail.com> wrote:

>>> def getArray(instrument, weekString=None):

>>> ...

>>> cur.execute(sql)

>>> weekData = cur.fetchall()

>>> wdata = []

>>> lst = []

>>> dtminute, dttypes = createDType()

>>> for i in dttypes:

>>> if i[1] == 'f8': lst.append(0.0)

>>> elif i[1] == 'i1': lst.append(0)

>>> else: lst.append('')

>>> for m in weekData:

>>> data = list(m)+lst[9:]

>>> wdata.append(data)

>>

>> I think "data" here should be a tuple, i.e. tuple(data)

>> structured arrays expect tuples for each element/row

>>

>> If this is not it, then you could provide a mini example of wdata with

>> just a few rows.

>>

>>> return np.array(wdata,dtype=dtminute)

>>>

>>> The createDType() function works fine. The getArray() function fails with:

>>> ValueError: Setting void-array with object members using buffer.

>>

>> cryptic exceptions messages in array construction usually means there

>> is some structure in the argument data that numpy doesn't understand,

>> I usually work with trial and error for a specific example

>>

>> Josef

>

> Hello Josef,

>

> Wrapping data, tuple(list(m)+lst[9:])

> works.

>

> Thanks.

>

> For some reason I was under the impression that numpy accepted either

> lists or tuples as long as the shape of the structure, and the data

> types was the same as the dtype array structure that it is filling.

> Is there a particular reason this is not so?

to have an n-dimensional structured array where each element is a

tuple.

So, I guess, numpy needs the distinction between list and tuples to

know what is an element.

That's from hitting at this very often, I never looked at the numpy

internals for this.

Josef

>

> Again, thanks. I can now get rid of my moderately less elegant, but

> working second version.

>

> Jimmie

>

> _______________________________________________

> NumPy-Discussion mailing list

> NumPy-Discussion@scipy.org

> http://mail.scipy.org/mailman/listinfo/numpy-discussion

>

_______________________________________________

NumPy-Discussion mailing list

NumPy-Discussion@scipy.org

http://mail.scipy.org/mailman/listinfo/numpy-discussion

vincent@vincentdavis.net | ||