On 9/7/06, Travis Oliphant <[EMAIL PROTECTED]> wrote:
Charles R Harris wrote:

>
>     So is this intentional?
>
>     In [24]: a = array([[],[],[]], dtype=object)
>
>     In [25]: a.shape
>     Out[25]: (3, 0)
>
>     In [26]: a = array([], dtype=object)
>
>     In [27]: a.shape
>     Out[27]: (0,)
>
>     One could argue that the first array should have shape (3,)
>
Yes, it's intentional because it's the old behavior of Numeric.  And it
follows the rule that object arrays don't do anything special unless the
old technique of using [] as 'dimension delimiters' breaks down.

>
> And this doesn't look quite right:
>
> In [38]: a = array([[1],[2],[3]], dtype=object)
>
> In [39]: a.shape
> Out[39]: (3, 1)
>
> In [40]: a = array([[1],[2,3],[4,5]], dtype=object)
>
> In [41]: a.shape
> Out[41]: (3,)
>

Again, same reason as before.  The first example works fine to construct
a rectangular array of object arrays of dimension 2.  The second only
does if we limit the number of dimensions to 1.

The rule is that array needs nested lists with the same number of
dimensions unless you have object arrays.  Then, the dimensionality will
be determined by finding the largest number of dimensions possible for
consistency of shape.

So there is a 'None' trick:

In [93]: a = array([[[2]], None], dtype=object)

In [94]: a[0]
Out[94]: [[2]]
 
I wonder if it wouldn't be useful to have a 'depth' keyword. Thus depth=None is current behavior, but

array([], depth=0)

would produce a zero dimensional array containing an empty list. Although I notice from playing with dictionaries that a zero dimensional array containing a dictionary isn't very useful.

array([[],[]], depth=1)

would produce a one dimensional array containing two empty lists, etc. I can see it is difficult to get something truely general with the current syntax without a little bit of extra information.

Another question, what property must an object possess to be a container type argument in array? There are sequence type objects, and array type objects. Are there more or is everything else treated as an object?

Chuck


-------------------------------------------------------------------------
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