@@ -202,30 +202,24 @@ def inverse(self):
202202 def ndindex (self ):
203203 """List the indexes corresponding to the space grid."""
204204 if self ._ndindex is None :
205- indexes = tuple ([np .arange (s ) for s in self ._shape ])
206- self ._ndindex = np .array (np .meshgrid (* indexes , indexing = "ij" )).reshape (
207- self ._ndim , self ._npoints
208- )
205+ indexes = np .mgrid [0 :self ._shape [0 ], 0 :self ._shape [1 ], 0 :self ._shape [2 ]]
206+ self ._ndindex = indexes .reshape ((indexes .shape [0 ], - 1 )).T
209207 return self ._ndindex
210208
211209 @property
212210 def ndcoords (self ):
213211 """List the physical coordinates of this gridded space samples."""
214212 if self ._coords is None :
215- self ._coords = np .tensordot (
216- self ._affine ,
217- np .vstack ((self .ndindex , np .ones ((1 , self ._npoints )))),
218- axes = 1 ,
219- )[:3 , ...]
213+ self ._coords = self .ras (self .ndindex )
220214 return self ._coords
221215
222216 def ras (self , ijk ):
223217 """Get RAS+ coordinates from input indexes."""
224- return _apply_affine (ijk , self ._affine , self ._ndim )
218+ return _apply_affine (ijk , self ._affine , self ._ndim ). T
225219
226220 def index (self , x ):
227221 """Get the image array's indexes corresponding to coordinates."""
228- return _apply_affine (x , self ._inverse , self ._ndim )
222+ return _apply_affine (x , self ._inverse , self ._ndim ). T
229223
230224 def _to_hdf5 (self , group ):
231225 group .attrs ["Type" ] = "image"
0 commit comments