NumExpr API

Numexpr is a fast numerical expression evaluator for NumPy. With it, expressions that operate on arrays (like “3*a+4*b”) are accelerated and use less memory than doing the same calculation in Python.


for more info about it.

numexpr.NumExpr(ex, signature=(), **kwargs)[source]

Compile an expression built using E.<variable> variables to a function.

ex can also be specified as a string “2*a+3*b”.

The order of the input variables and their types can be specified using the signature parameter, which is a list of (name, type) pairs.

Returns a NumExpr object containing the compiled function.


Detects the number of cores on a system. Cribbed from pp.


DEPRECATED: use _init_num_threads instead. If this is modified, please update the note in:


Given a NumExpr object, return a list which is the program disassembled.

numexpr.evaluate(ex, local_dict=None, global_dict=None, out=None, order='K', casting='safe', **kwargs)[source]

Evaluate a simple array expression element-wise, using the new iterator.

ex is a string forming an expression, like “2*a+3*b”. The values for “a” and “b” will by default be taken from the calling function’s frame (through use of sys._getframe()). Alternatively, they can be specifed using the ‘local_dict’ or ‘global_dict’ arguments.

local_dictdictionary, optional

A dictionary that replaces the local operands in current frame.

global_dictdictionary, optional

A dictionary that replaces the global operands in current frame.

outNumPy array, optional

An existing array where the outcome is going to be stored. Care is required so that this array has the same shape and type than the actual outcome of the computation. Useful for avoiding unnecessary new array allocations.

order{‘C’, ‘F’, ‘A’, or ‘K’}, optional

Controls the iteration order for operands. ‘C’ means C order, ‘F’ means Fortran order, ‘A’ means ‘F’ order if all the arrays are Fortran contiguous, ‘C’ order otherwise, and ‘K’ means as close to the order the array elements appear in memory as possible. For efficient computations, typically ‘K’eep order (the default) is desired.

casting{‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optional

Controls what kind of data casting may occur when making a copy or buffering. Setting this to ‘unsafe’ is not recommended, as it can adversely affect accumulations.

  • ‘no’ means the data types should not be cast at all.

  • ‘equiv’ means only byte-order changes are allowed.

  • ‘safe’ means only casts which can preserve values are allowed.

  • ‘same_kind’ means only safe casts or casts within a kind, like float64 to float32, are allowed.

  • ‘unsafe’ means any data conversions may be done.


Get the VML/MKL library version.


Re-evaluate the previous executed array expression without any check.

This is meant for accelerating loops that are re-evaluating the same expression repeatedly without changing anything else than the operands. If unsure, use evaluate() which is safer.

local_dictdictionary, optional

A dictionary that replaces the local operands in current frame.


Sets a number of threads to be used in operations.

DEPRECATED: returns the previous setting for the number of threads.

During initialization time NumExpr sets this number to the number of detected cores in the system (see detect_number_of_cores()).


Set the accuracy mode for VML operations.

The mode parameter can take the values: - ‘high’: high accuracy mode (HA), <1 least significant bit - ‘low’: low accuracy mode (LA), typically 1-2 least significant bits - ‘fast’: enhanced performance mode (EP) - None: mode settings are ignored

This call is equivalent to the vmlSetMode() in the VML library. See:

for more info on the accuracy modes.

Returns old accuracy settings.


Suggests a maximum number of threads to be used in VML operations.

This function is equivalent to the call mkl_domain_set_num_threads(nthreads, MKL_DOMAIN_VML) in the MKL library. See:

for more info about it.


The number of (virtual) cores detected.


The number of threads currently in-use.


The maximum number of threads, as set by the environment variable NUMEXPR_MAX_THREADS


The version of NumExpr.

Tests submodule


Print the versions of software that numexpr relies on.


Run all the tests in the test suite.