On Sat, May 15, 2010 at 9:27 AM, Jimmie Houchin email@example.com wrote:
On 5/15/2010 6:30 AM, firstname.lastname@example.org wrote:
On Sat, May 15, 2010 at 12:24 AM, Jimmie Houchinjlhouchin@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 == 'f8': lst.append(0.0) elif i == '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.
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
Wrapping data, tuple(list(m)+lst[9:]) works.
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?
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.
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.
Again, thanks. I can now get rid of my moderately less elegant, but working second version.
NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion