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!
slicehas 3 values - start, stop, step.jjwith anp.arangeorrangecall, it can be cast as aslice. But to understand the relative speed of slices, you have to understand the difference between aviewandcopy, and ultimately some idea of hownumpyusesstridesandshapeto view a flat data array as a multidimensional one.