On Tue, 2022-05-17 at 12:16 +0200, Andras Deak wrote:
> On Mon, May 16, 2022, at 17:54, Paul Korir wrote:
> > Hellos,
> > I would like to propose
> > `numpy.ndarray.permute_shape(<permuted_shape>)` 
> > method to predictably permute the shape of an ndarray. In my
> > opinion, 
> > the current alternatives (`swapaxes`, `transform`, `moveaxes` and 
> > friends) are counterintuitive and rely on referring to the axis 
> > indices. It would be abundantly helpful to have something like
> > reshape 
> > but which moves the data around (unlike reshape, which doesn't). 
> 
> Hi Paul,
> 
> Could you please show a small example of how `permute_shape()` is
> meant to work? It's not clear to me what it's meant to do, especially


An example would indeed be great, since it would make it much clearer
what operation you are looking for exactly (that is different from
transpose).

I suspect that another approach would be adding a syntax similar (or
identical) to einops to NumPy: https://github.com/arogozhnikov/einops/
which generalizes the einsum notation to allow e.g. comprehensive
reshaping.

Cheers,

Sebastian


> in contrast to `transpose` and `swapaxes` etc. "Like reshape" and
> "permute" together specifically sounds confusing to me. From your
> description of the problem I'd have thought that `transpose` (with a
> potential `copy`) would do what you need, so I'm probably
> misunderstanding your use case. What would it do when applied to a 3d
> array of, say, shape (2, 3, 5)?
> 
> AndrĂ¡s
> 
> > Scenario: structural biology uses MRC files, which define a number
> > of 
> > fields that describe a 3D volume. There is a field which describes
> > the 
> > dimensions of the 3D image and another which associates each image
> > axis 
> > with a physical axis. There are six such assignments between the
> > image 
> > shape and the axes assignments (if we keep the shape fixed we can 
> > assign XYZ, XZY, YXZ, YZX, ZXY, ZYX to the columns, rows and
> > stacks) 
> > and working out how to correctly transform the data is generally 
> > non-trivial. I've written a package 
> > (https://github.com/emdb-empiar/maptools) which does this but I use
> > swapaxes to reorient the 3D image. It would be so much easier to
> > use 
> > `numpy.ndarray.permute_shape(<permuted_shape>)` instead.
> > Any thoughts? Also, any helpful hints on how to get started with
> > such a 
> > contribution would be helpful.
> > Paul
> > _______________________________________________
> > NumPy-Discussion mailing list -- numpy-discussion@python.org
> > To unsubscribe send an email to numpy-discussion-le...@python.org
> > https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
> > Member address: deak.and...@gmail.com
> _______________________________________________
> NumPy-Discussion mailing list -- numpy-discussion@python.org
> To unsubscribe send an email to numpy-discussion-le...@python.org
> https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
> Member address: sebast...@sipsolutions.net


_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to