I am attempting to extract values from a 3d numpy array. At the moment I can perform the following operations:
newmesh.shape
(40,40,40)
newmesh[2,5,6]
6
newmesh[np.array([2,5,6])].shape
(3, 42, 42)
np.take(newmesh,np.array([2,5,6]))
[1 1 1]
With idx
as the (n,3)
indexing array, one approach using linearindexing
would be with np.ravel_multi_index

np.take(newmesh,np.ravel_multi_index(idx.T,newmesh.shape))
An approach with tuple formation would look like this 
newmesh[tuple(idx.T)]
If there are just three dimensions, you can even just use columnar slices for indexing into each dimension, like so 
newmesh[idx[:,0],idx[:,1],idx[:,2]]
Runtime test If anyone's interested in seeing the performance numbers associated with the listed approaches, here's a quick runtime test 
In [18]: newmesh = np.random.rand(40,40,40)
In [19]: idx = np.random.randint(0,40,(1000,3))
In [20]: %timeit np.take(newmesh,np.ravel_multi_index(idx.T,newmesh.shape))
10000 loops, best of 3: 22.5 µs per loop
In [21]: %timeit newmesh[tuple(idx.T)]
10000 loops, best of 3: 20.9 µs per loop
In [22]: %timeit newmesh[idx[:,0],idx[:,1],idx[:,2]]
100000 loops, best of 3: 17.2 µs per loop