You're right that for math expressions, it is nice to have them in the
namespace, so this is used a lot:from numpy import sqrt, sin, cos, exp
Maybe it's a reasonable idea to write a Nmath.py, which would have an
import line like that.Out of 491 names in the numpy namespace, I found 26 that would commonly
be found in math expressions. Not bad, really, much better than
including all 491.Inf NaN abs angle arccos arccosh arcsin arcsinh arctan
arctan2 arctanh cos cosh exp log log10 pi sign sin
sinc sinh sqrt square tan tanh
The C99 math/complex headers define a number of symbols.
constants:
log: M_E M_LOG2E M_LOG10E M_LN2 M_LN10
pi: M_PI M_PI_2 M_PI_4 M_1_PI M_2_PI M_2_SQRTPI
sqrt(2): M_SQRT2 M_SQRT1_2
functions:
isfinite isnormal isnan isinf
acos asin atan atan2 cos sin tan
acosh asinh atanh cosh sinh tanh
exp log log10 expm1 log1p exp2 log2
pow sqrt cbrt erf erfc lgamma tgamma hypot
fmod remainder remquo
fabs fdim fmax fmin
copysign signbit frexp ldexp logb modf scalbn
ceil floor rint nexttoward nearbyingt round trunc
complex functions:
acos asin atan atan2 cos sin tan
acosh asinh atanh cosh sinh tanh
exp log pow sqrt
conj cproj abs arg imag real
The glibc header files are not the most concise source so likely I've
made mistakes (e.g., missing inf/nan defs) and included things that
are not actually standard (e.g., hypot?). Making a lot of these available
in mpl.math would be nice.
Short of installing all of scipy, anyone know where I can pick up erf()?
> I'm guessing a function sqrt(-1.) which returns 1j is out of the question?
what's wrong with "1j" as a literal?
Let me rephrase: Can we have a function sqrt(x) which returns real if x is
nonnegative, and complex if it is negative? Similarly for other math functions
such as log which produce complex values for negative numbers?
I suppose the numpy list is the place to debate this, but it seems like it
ought to be a feature of pylab in as much as pylab helps matlab users do
pythonic things in a familiar environment.
- Paul
···
On Fri, Jul 20, 2007 at 12:34:44PM -0700, Christopher Barker wrote: