Subject: ?Numpy: number of elements in an array?

Chris Barker chrishbarker at home.net
Thu Jun 21 15:43:35 EDT 2001


Norman Shelley wrote:
> In Numpy how does one get the number of elements in an array?
> 
> This seems to do it
> reduce(mul, a.shape, 1)

A little simpler:

product(a.shape)

or:

len(a.flat)

 > but shouldn't there be a straight forward, function/method to do it?

maybe, but it is probably pretty rare to want to know the number of
elements without needing to know the shape.

-Chris

-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list