mirror of
https://github.com/meteoinfo/MeteoInfo.git
synced 2025-12-08 20:36:05 +00:00
20 lines
555 B
Python
20 lines
555 B
Python
|
|
import mipylib.numeric as np
|
|
|
|
__all__ = ['broadcast_indices']
|
|
|
|
def broadcast_indices(x, minv, ndim, axis):
|
|
"""Calculate index values to properly broadcast index array within data array.
|
|
|
|
See usage in interp.
|
|
"""
|
|
ret = []
|
|
for dim in range(ndim):
|
|
if dim == axis:
|
|
ret.append(minv)
|
|
else:
|
|
broadcast_slice = [np.newaxis] * ndim
|
|
broadcast_slice[dim] = slice(None)
|
|
dim_inds = np.arange(x.shape[dim])
|
|
ret.append(dim_inds[tuple(broadcast_slice)])
|
|
return tuple(ret) |