In my application A
and jj
are given as flattened, 1-dim numpy
arrays. jj
has not a strictly regular pattern. We can address the slice jj
of A
with:
A = np.arange(10)
jj = np.array([3,5,6])
A[jj]
This is called 'fancy slicing' and is told to be slow. Is there a way to speed up the access with something like:
A = np.arange(10)
jj = np.array([3,5,6])
ii = slice(jj)
A[ii]
This example does not work, but perhaps there is another lean way. The slice-command is fast and attractive. Is there a way to cast the jj
numpy-array into a slice(jj)
with a gain of efficiency?
My context is to build repeated a large system matrix in computational fluid dynamics with variable coefficients. Thanks for some hints!