reshape() (was Re: Fw: Wrapup time)
[email protected] ("Jeremy Howard") Thu, 14 Sep 2000 08:58:42 +1100
| Newsgroups | perl.perl6.language.data |
|---|---|
| Message-ID | <[email protected]> |
Nathan Wiger wrote: > Jeremy Howard wrote: > > > > 148: Change to Numeric Python semantics of reshape(), or write counter-RFC > > specifying these semantics (preferably renaming this RFC's 'reshape' to > > something else) > > There are a couple things that the NumPy one lacks that RFC 148 > currently has: > > 1. Arbitrary Interleaving > > 2. A way to specify multiple @arrays, i.e. > > @new = reshape $x,$y,$i, @a, @b, @c; # RFC 148 > > Now, if we're looking for a new, more compact syntax, let's make arg one > an arrayref of dimensions: > > @new = reshape [$x,$y,$i], @a, @b, @c; > > That looks remarkably similar to NumPy's, plus it can take multiple > arrays, even defaulting to @_. And I can change the "wildcard" from 0 to > -1, just like NumPy's. > That looks good, except that I'd remove the interleaving. Currently, it's not clear how to reshape() to more than 2 dimensions, because the third argument of the first list ref is the interleave flag. We should be able to be able to reshape to any number of dimensions: @new = reshape [$w,$x,$y,$z], @a, @b, @c; Furthermore, it's not clear how interleaving would work on >2d arrays. I'd rather use a transpose() function for this that can transpose across a given axis. I don't think we need to define the ability to work on multiple lists as special behaviour. Perl knows how to flatten lists, so any syntax we define will allow multiple lists simply by letting Perl join and flatten them. Finally, I think the dimensions specified by reshape() should be the maximum index of the axis, not the number of elements, since this way it matches the :bounds semantics. In this case, the wildcard would clearly need to -1. Then I'd be happy. ;-)