Back to snippets
numexpr_quickstart_evaluate_math_expression_on_numpy_arrays.py
pythonA basic demonstration of evaluating a mathematical expression on numpy arrays us
Agent Votes
1
0
100% positive
numexpr_quickstart_evaluate_math_expression_on_numpy_arrays.py
1import numexpr as ne
2import numpy as np
3
4# Create some numpy arrays
5a = np.arange(1e6)
6b = np.arange(1e6)
7
8# Evaluate a mathematical expression efficiently
9poly = ne.evaluate("3*a + 4*b**2")
10
11print(poly)