Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

rank-0 arrays?

0 views
Skip to first unread message

brobb...@shaw.ca

unread,
Sep 30, 2002, 12:53:13 PM9/30/02
to
In Numeric Python, what are rank-0 arrays?
Must not arrays have at least 1 dimension?

BR

Steve Holden

unread,
Sep 30, 2002, 1:35:47 PM9/30/02
to
<brobb...@shaw.ca> wrote in message news:3d988160.79509684@news...

> In Numeric Python, what are rank-0 arrays?
> Must not arrays have at least 1 dimension?
>

Only if they must contain data. A xero-rank array will (sort of) be the None
of Numeric arrays.

regards
-----------------------------------------------------------------------
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/
Previous .sig file retired to www.homeforoldsigs.com
-----------------------------------------------------------------------

Pearu Peterson

unread,
Sep 30, 2002, 1:47:25 PM9/30/02
to

On 30 Sep 2002, Steve Holden wrote:

> <brobb...@shaw.ca> wrote in message news:3d988160.79509684@news...
> > In Numeric Python, what are rank-0 arrays?
> > Must not arrays have at least 1 dimension?
> >
>
> Only if they must contain data. A xero-rank array will (sort of) be the None
> of Numeric arrays.

This is not correct.
In Numeric Python rank-0 arrays are like mutable scalars.

Pearu


Carl Banks

unread,
Sep 30, 2002, 2:03:43 PM9/30/02
to
brobb...@shaw.ca wrote:
> In Numeric Python, what are rank-0 arrays?
> Must not arrays have at least 1 dimension?

Well, in mathematics, a rank-0 array is a scalar, which is considered
a degenerate array. The reason rank-0 arrays exist is because there
are some operations that produce arrays of various rank depending on
the rank of the operands, and in many cases these operations can
produce arrays of rank 0.

For example, consider cartesian tensors, which can be represented by
Numeric arrays. Cartesian tensors have an operation called inner
product, which multiplies a rank-n tensor by a rank-m tensor to
produce a tensor of rank abs(n-m). (I'm probably simplifying this too
much.) Anyways, suppose you want the inner product of two rank-1
tensors (i.e., vectors). The result is a rank-0 tensor, i.e., a
scalar.

Another example is a trace operation, which takes a tensor of rank n,
and produces a tensor of rank (n-2). The trace of a rank-2 tensor is,
as with matrices, a scalar.

Evidently, Numeric supports rank-0 arrays to allow these operations to
be done consistently, without special exceptions to handle degenerate
cases.

However, IIRC, it is good advice not to play around too much with
rank-0 arrays in Python. They should be converted to regular Python
floats if you're going to do something non-Numeric with them.

--
CARL BANKS
http://www.aerojockey.com

0 new messages