[Numpy-discussion] np.where and broadcasting

Pauli Virtanen pav at iki.fi
Mon Oct 10 17:14:04 EDT 2011


10.10.2011 23:02, Jesper Larsen kirjoitti:
> Hi numpy-users
>
> I have a 2d array of shape (ny, nx). I want to broadcast (copy) this
> array to a target array of shape (nt, nz, ny, nz) or (nt, ny, nx) so
> that the 2d array is repeated for each t and z index (corresponding to
> nt and nz). I am not sure how to do this (generic solution, for
> different target array shapes). Can anyone help?

assert a.shape == (nt, nz, ny, nx) or a.shape == (nt, ny, nx)
assert b.shape == (ny, nx)
a[...] = b




More information about the NumPy-Discussion mailing list