
On 5/15/2010 6:30 AM, josef.pktd@gmail.com 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[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?
Again, thanks. I can now get rid of my moderately less elegant, but working second version.
Jimmie