`Numeric`

supplies named functions with the same semantics as Python’s arithmetic, comparison, and bitwise operators, and mathematical functions like those supplied by built-in modules `math`

and `cmath`

(covered in The math and cmath Modules), such as `sin`

, `cos`

, `log`

, and `exp`

.

These functions are objects of type `ufunc`

(which stands for “universal function”) and share several traits in addition to those they have in common with array operators (element-wise operation, broadcasting, coercion). Every `ufunc`

instance * u* is callable, is applicable to sequences as well as to arrays, and accepts an optional

`output`

`u`

`u`

`u`

`u`

`.accumulate`

, `u`

`.outer`

, `u`

`.reduce`

, and `u`

`.reduceat`

. The `ufunc`

objects supplied by `Numeric`

apply only to arrays with numeric typecodes (i.e., not to arrays with typecode `'O'`

or `'c'`

) and Python sequences of numbers.When you start with a list * L*, it’s faster to call

`u`

`L`

`L`

`u`

`a`

`a`

`tolist`

. For example, say you must compute the logarithm of each item of a list and return another list. On my laptop, with `N`

set to `2222`

, a list comprehension such as:def logsupto(N): return [math.log(x) for x in range(2,N)]

takes about 5.2 milliseconds. Using Python’s ...

Start Free Trial

No credit card required