[Numpy-discussion] the mean, var, std of non-arrays
lists at onerussian.com
Thu Jul 18 22:49:20 EDT 2013
Some of my elderly code stopped working upon upgrades of numpy and
upcoming pandas: https://github.com/pydata/pandas/issues/4290 so I have
looked at the code of
2481 def mean(a, axis=None, dtype=None, out=None, keepdims=False):
2491 a : array_like
2492 Array containing numbers whose mean is desired. If `a` is not an
2493 array, a conversion is attempted.
2556 if type(a) is not mu.ndarray:
2558 mean = a.mean
2559 return mean(axis=axis, dtype=dtype, out=out)
2560 except AttributeError:
2563 return _methods._mean(a, axis=axis, dtype=dtype,
2564 out=out, keepdims=keepdims)
here 'array_like'ness is checked by a having mean function. Then it is assumed
that it has the same definition as ndarray, including dtype keyword argument.
Not sure anyways if my direct numpy.mean application to pandas DataFrame is
"kosher" -- initially I just assumed that any argument is asanyarray'ed first
-- but I think here catching TypeError for those incompatible .mean's would not
hurt either. What do you think? Similar logic applies to mean cousins (var,
std, ...?) decorated around _methods implementations.
Yaroslav O. Halchenko, Ph.D.
http://neuro.debian.net http://www.pymvpa.org http://www.fail2ban.org
Senior Research Associate, Psychological and Brain Sciences Dept.
Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755
Phone: +1 (603) 646-9834 Fax: +1 (603) 646-1419
More information about the NumPy-Discussion