I don’t know about efficient, but you could use np.vectorize
on the .get
method of dictionaries:
>>> a = np.array([[1,2,3],
[3,2,4]])
>>> my_dict = {1:23, 2:34, 3:36, 4:45}
>>> np.vectorize(my_dict.get)(a)
array([[23, 34, 36],
[36, 34, 45]])
More Related Contents:
- Convert a 3D array to RGB valued array [closed]
- Unable to allocate array with shape and data type
- Coalesce values from 2 columns into a single column in a pandas dataframe
- scipy: savefig without frames, axes, only content
- Interpolate NaN values in a numpy array
- Pandas: Subtracting two date columns and the result being an integer
- Numpy ‘smart’ symmetric matrix
- Fitting a 2D Gaussian function using scipy.optimize.curve_fit – ValueError and minpack.error
- No module named when using PyInstaller
- How can I use numpy.correlate to do autocorrelation?
- ‘DataFrame’ object has no attribute ‘sort’
- Immutable numpy array?
- N-D version of itertools.combinations in numpy
- figure of imshow() is too small
- Binary random array with a specific proportion of ones?
- python recursive vectorization with timeseries
- Difference between np.random.seed() and np.random.RandomState()
- Loading UTF-8 file in Python 3 using numpy.genfromtxt
- What does a colon and comma stand in a python list?
- convert string representation of array to numpy array in python
- How to share numpy random state of a parent process with child processes?
- Flattening a list of NumPy arrays?
- Fastest pairwise distance metric in python
- How do I get Pylint to recognize NumPy members?
- Is there an analysis speed or memory usage advantage to using HDF5 for large array storage (instead of flat binary files)?
- python tilde unary operator as negation numpy bool array
- Sieve of Eratosthenes – Primes between X and N
- Split Python sequence (time series/array) into subsequences with overlap
- numpy arange: how to make “precise” array of floats?
- Sort array’s rows by another array in Python