Greetings! I'm having trouble using records. I'm not sure whether to report this as a bug, but it certainly isn't a feature! I would like to be able to iterate over the individual rows in a record array, like so:
>>> import numpy.core.records as rec >>> x=rec.array([[1,1.1,'1.0'],[2,2.2,'2.0']], formats='i4,f8,a4',names=['i','f','s']) >>> type(x[0]) <class 'numpy.core.records.record'> >>> x[0].tolist() Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: can't convert a 0-d array to a list >>> [i for i in x[0]] Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: iteration over non-sequence Am I going about this wrong? I would think I should be able to loop over an individual row in a record array, or turn it into a list. For the latter, I wrote my own thing, but tolist() should work by itself. Note that in rec2list, I need to use range(len(line)) because the list comprehension doesn't work correctly: def rec2list(line): """Turns a single element record array into a list.""" return [line[i] for i in xrange(len(line))] #... I will file a bug, unless someone tells me I'm going about this the wrong way. Thanks for your help John -- ************************* John Parejko Department of Physics and Astronomy Drexel University Philadelphia, PA ************************** 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