25.3 Supported NumPy Features 291
including construction, unpacking and iteration across the elements of a tuple. lists are supported but
only if they contain a homogeneous data type. In general, it is better to use a NumPy array than a list since
the generality of lists imposes additional overheads. sets are also supported but only if homogeneous.
Many of the built-in functions are supported including bool, int, float, complex, len, enumerate, and
range. Many functions in the cmath and math modules are supported such as abs, exp, log and trigonomet-
ric functions. Many of the same functions are supported if imported from NumPy, and so it isn’t strictly
necessary to use these modules unless intentionally avoiding NumPy. Many functions from the standard
library random are also available. However, since the same functions are also supported when imported
from NumPy, there is little reason to use the standard library’s random module.
25.3 Supported NumPy Features
Numba is continually evolving and generally releases a new version monthly. This section focuses on a
subset of available features and the full, up-to-date list of available features is available in the Numba
documentation (http://numba.pydata.org).
Numba has added support for a large swath of NumPy features including array creation, array con-
catenation, core mathematical functions, nearly all NumPy ufuncs
2
, the NumPy random number gener-
ator (numpy.random) and a core subset of the linear algebra module (numpy.linalg). While the support for
NumPy is fairly pervasive, there are many caveats and it isn’t reasonable to expect a complex function,
even if NumPy only, to be supported. For example, many of the supported functions only support the
most common inputs, linear algebra support is only available for 1- and 2-dimensional arrays containing
single-precision, double-precision, or complex arrays, and in many cases automatic type promotion is
not implemented (e.g. functions that accept double-prevision but return complex in certain cases).
Array Creation and Concatenation
Direct creation of arrays using array is supported. Creating multidimensional arrays is supported al-
though these must be constructed using nested tuples rather than nested lists. Standard methods of
special arrays including empty, zeros, ones, and fill are all supported. The *_like methods are also sup-
ported (e.g., empty_like). These all support only 2 input – the required input (either object or shape) and the
dtype (fill also accepts the fill values). Other array creation methods supported include arange, linspace,
eye, and identity. These also have limitations The common array concatenation function, concatenate,
column_stack, dstack, hstack, and vstack are all supported.
Array Properties and Functions
Most array properties such as ndim, size, shape, dtype, and T (transpose) are supported, as are most array
methods are supported, including
all, any, argmax, argmin, cumprod, cumsum, max, mean
min, nonzero, prod, std, sum, var
2
A NumPy ufunc is a function that operated element by element and supports broadcasting when called with more than one
input. Leading examples of ufuncs include exp, log, sqrt, isnan, trigonometric functions the logical functions (e.g., sin, cos,
etc.) and the logical functions (e.g., logical_and, logical_or, etc.).