apply table lookup to each element
Suggestion for efficient way to apply a table lookup to each element of an integer array? import numpy as np _cos = np.empty ((2**rom_in_bits,), dtype=int) _sin = np.empty ((2**rom_in_bits,), dtype=int) for address in xrange (2**12): _cos[address] = nint ((2.0**(rom_out_bits-1)-1) * cos (2 * pi * address * (2.0**-rom_in_bits))) _sin[address] = nint ((2.0**(rom_out_bits-1)-1) * sin (2 * pi * address * (2.0**-rom_in_bits))) Now _cos, _sin are arrays of integers (quantized sin, cos lookup tables) How to apply _cos lookup to each element of an integer array: phase = np.array (..., dtype =int) cos_out = lookup (phase, _cos) ???
Neal Becker wrote:
Suggestion for efficient way to apply a table lookup to each element of an integer array?
import numpy as np _cos = np.empty ((2**rom_in_bits,), dtype=int) _sin = np.empty ((2**rom_in_bits,), dtype=int) for address in xrange (2**12): _cos[address] = nint ((2.0**(rom_out_bits-1)-1) * cos (2 * pi * address * (2.0**-rom_in_bits))) _sin[address] = nint ((2.0**(rom_out_bits-1)-1) * sin (2 * pi * address * (2.0**-rom_in_bits)))
Now _cos, _sin are arrays of integers (quantized sin, cos lookup tables)
How to apply _cos lookup to each element of an integer array:
phase = np.array (..., dtype =int) cos_out = lookup (phase, _cos) ???
Turns out that if A is an np.array and B is an np.array, then A[B] will do exactly what I wanted. Is this mentioned anywhere in the documentation?
2009/5/4 Neal Becker <ndbecker2@gmail.com>:
Turns out that if A is an np.array and B is an np.array, then A[B] will do exactly what I wanted.
Is this mentioned anywhere in the documentation?
http://docs.scipy.org/numpy/docs/numpy-docs/reference/arrays.indexing.rst/#a... Stéfan
participants (2)
-
Neal Becker
-
Stéfan van der Walt