[Numpy-discussion] Shapes and sizes
Albert Strasheim
fullung at gmail.com
Fri Feb 24 11:44:05 EST 2006
Hello
On Fri, 24 Feb 2006, Sasha wrote:
> On 2/24/06, Sasha <ndarray at mac.com> wrote:
> > Try
> > >>> empty(map(outsize, arra.shape))
> Oops. I did not realize that you want to apply outsize to the last
> dimension only. For ndim>1, you can do
>
> >>> empty(arra.shape[:-1]+(outsize(arra.shape[-1]),))
Thanks, this works nicely. My code:
outsize = lambda n: (n/2+1, (n+1)/2)[(n%2)%2]
b = empty(a.shape[:-1]+(outsize(a.shape[-1]),))
(One line less than MATLAB ;-))
> That will not work work for scalars though, but you might want to
> rethink whether your function makes sense for scalars. Remember, 1 is
> not the same as [1] in python, you maybe trying to copy MATLAP design
> too literally.
Personally, I think asarray(scalar) should return something that can
actually be used as an array (i.e. has a proper shape and ndim), but
if all NumPy functions operate only on arrays to begin with, I could
live with that too.
Regards
Albert
More information about the NumPy-Discussion
mailing list