Hello everyone,

I had quite some trouble figuring out the _correct_ way to create 
heterogeneous arrays.

What I wanted to do was something like the following:

 >>>  numpy.array( [(0,0,0)], dtype={'names':['a','b','c'], 
'formats':['f4','f4','f4']})

This works fine. Now, let's do something wrong, e.g. leave out the 
'formats' specifier:

 >>> numpy.array( [(0,0,0)], dtype={'names':['a','b','c']})
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/site-packages/numpy/core/_internal.py", line 
53, in _usefields
    names, formats, offsets, titles = _makenames_list(adict)
  File "/usr/lib/python2.4/site-packages/numpy/core/_internal.py", line 
21, in _makenames_list
    raise ValueError, "entry not a 2- or 3- tuple"
ValueError: entry not a 2- or 3- tuple

This error message was totally unclear to me. After reading a little on 
the scipy wiki I finally realized that (maybe) numpy internally converts 
the dict with the names and the formats to a list of 2-tuples of the 
form (name, format). Since no formats were given, these 2-tuples were 
invalid.

I would suggest a check for the required dict keys and some meaningful 
error message like: "The dtype dictionary must at least contain the 
'names' and the 'formats' items."

Keep up the great work,

Niklas.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion

Reply via email to