2.7. Supported NumPy features


NumPy support in Numba comes in many forms:



2.7.1. Scalar types

Numba supports the following Numpy scalar types:

  • Booleans
  • Datetimes and timestamps: of any unit
  • Character sequences (but no operations are available on them)

The following scalar types and features are not supported:

  • Arbitrary Python objects
  • Half-precision and extended-precision real and complex numbers

The operations supported on NumPy scalars are almost the same as on the equivalent built-in types such as int or float. You can use a type’s constructor to convert from a different type or width. In addition you can use the view(np.<dtype>) method to bitcast all int and float types within the same width. However, you must define the scalar using a NumPy constructor within a jitted function. For example, the following will work:

>>> import numpy as np
>>> from numba import njit
>>> @njit
... def bitcast():
...     i = np.int64(-1)
...     print(i.view(np.uint64))
>>> bitcast()

Whereas the following will not work:

>>> import numpy as np
>>> from numba import njit
>>> @njit
... def bitcast(i):
...     print(i.view(np.uint64))
>>> bitcast(np.int64(-1))
TypingError                               Traceback (most recent call last)
TypingError: Failed in nopython mode pipeline (step: ensure IR is legal prior to lowering)
'view' can only be called on NumPy dtypes, try wrapping the variable with 'np.<dtype>()'

File "<ipython-input-3-fc40aaab84c4>", line 3:
def bitcast(i):


See also

Numpy scalars reference.

2.7.2. Array types



See also

Numpy indexing reference. Attributes

The following attributes of Numpy arrays are supported: The flags object


The object returned by the flat attribute supports iteration and indexing, but be careful: indexing is very slow on non-C-contiguous arrays. The real and imag attributes

Numpy supports these attributes regardless of the dtype but Numba chooses to limit their support to avoid potential user error. For numeric dtypes, Numba follows Numpy’s behavior. The real attribute returns a view of the real part of the complex array and it behaves as an identity function for other numeric dtypes. The imag attribute returns a view of the imaginary part of the complex array and it returns a zero array with the same shape and dtype for other numeric dtypes. For non-numeric dtypes, including all structured/record dtypes, using these attributes will result in a compile-time (TypingError) error. This behavior differs from Numpy’s but it is chosen to avoid the potential confusion with field names that overlap these attributes. Calculation


The corresponding top-level Numpy functions (such as numpy.prod()) are similarly supported. Other methods

The following methods of Numpy arrays are supported:

  • argsort() (kind key word argument supported for values 'quicksort' and 'mergesort')
  • astype() (only the 1-argument form)
  • copy() (without arguments)
  • dot() (only the 1-argument form)
  • flatten() (no order argument; ‘C’ order only)
  • item() (without arguments)
  • itemset() (only the 1-argument form)
  • ravel() (no order argument; ‘C’ order only)
  • repeat() (no axis argument)
  • reshape() (only the 1-argument form)
  • sort() (without arguments)
  • sum() (with or without the axis argument)
    • If the axis argument is a compile-time constant, all valid values are supported. An out-of-range value will result in a LoweringError at compile-time.
    • If the axis argument is not a compile-time constant, only values from 0 to 3 are supported. An out-of-range value will result in a runtime exception.
  • transpose()
  • view() (only the 1-argument form)


Sorting may be slightly slower than Numpy’s implementation.

2.7.3. Functions Linear algebra



The implementation of these functions needs Scipy 0.16+ to be installed. Reductions

The following reduction functions are supported: Other functions

The following top-level functions are supported:

The following constructors are supported, both with a numeric input (to construct a scalar) or a sequence (to construct an array):

  • numpy.bool_
  • numpy.complex64
  • numpy.complex128
  • numpy.float32
  • numpy.float64
  • numpy.int8
  • numpy.int16
  • numpy.int32
  • numpy.int64
  • numpy.intc
  • numpy.intp
  • numpy.uint8
  • numpy.uint16
  • numpy.uint32
  • numpy.uint64
  • numpy.uintc
  • numpy.uintp

The following machine parameter classes are supported, with all purely numerical attributes: Literal arrays

Neither Python nor Numba has actual array literals, but you can construct arbitrary arrays by calling numpy.array() on a nested tuple:

a = numpy.array(((a, b, c), (d, e, f)))

(nested lists are not yet supported by Numba)

2.7.4. Modules random


The following functions are supported. Initialization Permutations stride_tricks

The following function from the numpy.lib.stride_tricks module is supported:

  • as_strided() (the strides argument is mandatory, the subok argument is not supported)

2.7.5. Standard ufuncs



name object mode nopython mode
add Yes Yes
subtract Yes Yes
multiply Yes Yes
divide Yes Yes
logaddexp Yes Yes
logaddexp2 Yes Yes
true_divide Yes Yes
floor_divide Yes Yes
negative Yes Yes
power Yes Yes
remainder Yes Yes
mod Yes Yes
fmod Yes Yes
abs Yes Yes
absolute Yes Yes
fabs Yes Yes
rint Yes Yes
sign Yes Yes
conj Yes Yes
exp Yes Yes
exp2 Yes Yes
log Yes Yes
log2 Yes Yes
log10 Yes Yes
expm1 Yes Yes
log1p Yes Yes
sqrt Yes Yes
square Yes Yes
reciprocal Yes Yes
conjugate Yes Yes Trigonometric functions

name object mode nopython mode
sin Yes Yes
cos Yes Yes
tan Yes Yes
arcsin Yes Yes
arccos Yes Yes
arctan Yes Yes
arctan2 Yes Yes
hypot Yes Yes
sinh Yes Yes
cosh Yes Yes
tanh Yes Yes
arcsinh Yes Yes
arccosh Yes Yes
arctanh Yes Yes
deg2rad Yes Yes
rad2deg Yes Yes
degrees Yes Yes
radians Yes Yes Bit-twiddling functions

name object mode nopython mode
bitwise_and Yes Yes
bitwise_or Yes Yes
bitwise_xor Yes Yes
bitwise_not Yes Yes
invert Yes Yes
left_shift Yes Yes
right_shift Yes Yes Comparison functions

name object mode nopython mode
greater Yes Yes
greater_equal Yes Yes
less Yes Yes
less_equal Yes Yes
not_equal Yes Yes
equal Yes Yes
logical_and Yes Yes
logical_or Yes Yes
logical_xor Yes Yes
logical_not Yes Yes
maximum Yes Yes
minimum Yes Yes
fmax Yes Yes
fmin Yes Yes Floating functions

name object mode nopython mode
isfinite Yes Yes
isinf Yes Yes
isnan Yes Yes
signbit Yes Yes
copysign Yes Yes
nextafter Yes Yes
modf Yes No
ldexp Yes (*) Yes
frexp Yes No
floor Yes Yes
ceil Yes Yes
trunc Yes Yes
spacing Yes Yes

(*) not supported on windows 32 bit