min/max not exported in "from numpy import *"
Hi, I'm using 0.9.8 and find numpy.ndarray.min() is not exported to global space when doing a from numpy import * In [1]: from numpy import * In [2]: help min ------> help(min) Help on built-in function min in module __builtin__: min(...) min(sequence) -> value min(a, b, c, ...) -> value With a single sequence argument, return its smallest item. With two or more arguments, return the smallest argument. Also numpy.ndarray.max() is not available too. But the built-in sum() is replaced by numpy.ndarray.sum() as expected. Is this a bug or just intended to do so and user has to use numpy.ndarray.min() explicitly? Cheers, Zhang Le
Zhang> I'm using 0.9.8 and find numpy.ndarray.min() is not exported to Zhang> global space when doing a Zhang> from numpy import * I'm going to take a wild-ass guess and suggest that was a concious decision by the authors. Shadowing builtins is generally a no-no. You just need to be explicit instead of implicit: from numpy import min, max Skip
I'm going to take a wild-ass guess and suggest that was a concious decision by the authors. Shadowing builtins is generally a no-no. You just need to be explicit instead of implicit:
from numpy import min, max I see. But why by default sum is exported? Is that a wise decision?
In [1]: from numpy import * In [2]: help sum ------> help(sum) Help on function sum in module numpy.core.oldnumeric: sum(x, axis=0, dtype=None) ... Zhang Le
Zhang Le wrote:
I'm going to take a wild-ass guess and suggest that was a concious decision by the authors. Shadowing builtins is generally a no-no. You just need to be explicit instead of implicit:
from numpy import min, max
I see. But why by default sum is exported? Is that a wise decision?
In [1]: from numpy import *
In [2]: help sum ------> help(sum) Help on function sum in module numpy.core.oldnumeric:
sum(x, axis=0, dtype=None) ...
Zhang Le
Zhang: The reason max and min are not imported by 'from numpy import *' is because there are no such functions in numpy. They are ndarray methods now (a.max(), a.min()), there is also a maximum and minium function which behaves somewhat differently. There is still a sum function as you have discovered, and it will clobber the builtin. Another good reason not to use 'from numpy import *' -Jeff -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@noaa.gov 325 Broadway Office : Skaggs Research Cntr 1D-124 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
Zhang Le wrote:
I'm going to take a wild-ass guess and suggest that was a concious decision by the authors. Shadowing builtins is generally a no-no. You just need to be explicit instead of implicit:
from numpy import min, max
I see. But why by default sum is exported? Is that a wise decision?
Well, Numeric had the sum function long before Python introduced one. NumPy adopted Numeric's sum function as well. -Travis
Travis Oliphant wrote:
Well, Numeric had the sum function long before Python introduced one. NumPy adopted Numeric's sum function as well.
Yet another reason to NEVER use "import *" -CHB -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
participants (5)
-
Christopher Barker -
Jeff Whitaker -
skip@pobox.com -
Travis Oliphant -
Zhang Le