Bulba! wrote:
On Wed, 05 Jan 2005 17:25:08 -0800, Robert Kern <[EMAIL PROTECTED]>
wrote:

I still think numarray is a good start for this. It handles more than just numbers. And RecArray (an array that has different types in each column, as you seem to require) can be subclassed to add these methods to it.


I have downloaded it, playing with it and like it. I esp. like things
like:


print a + a

[2 4 6]

or


b.getshape()

(4,3)

Very Pythonic. :-)

However, not all things are generic enough like I meant. That
is not to criticize, but merely to point out that the library is for
obvious reasons slanted towards numerical work, so e.g. while the
following works:

.>>> from numarray import transpose
.>>> transpose([[1,2],[3,4]])
array([[1, 3],
       [2, 4]])

...this doesn't:


transpose([('phone1', 12345), ('phone2', 67890)])

Traceback (most recent call last): File "<interactive input>", line 1, in ? [....] TypeError: Expecting a python numeric type, got something else.

Why would someone want to do such a thing: suppose he
wants 'phone1' and 'phone2' and number records sequenced horizontally instead vertically, while when he read that from
a file, such was the file structure. It's a boneheaded example, but you get the idea.

http://stsdas.stsci.edu/numarray/numarray-1.1.html/module-numarray.objects.html

In [1]: from numarray import objects, transpose

In [2]: a = objects.array([['phone1', 12345], ['phone2', 67890]])

In [3]: a
Out[3]:
ObjectArray([['phone1', 12345],
             ['phone2', 67890]])

In [4]: transpose(a)
Out[4]:
ObjectArray([['phone1', 'phone2'],
             [12345, 67890]])

Note the use of lists. Using tuples makes the constructor think you want a vector of tuple objects.

--
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to