[Numpy-discussion] Raveling, reshape order keyword unnecessarily confuses index and memory ordering
josef.pktd@gmai...
josef.pktd@gmai...
Thu Apr 4 18:13:31 CDT 2013
On Thu, Apr 4, 2013 at 5:54 PM, Chris Barker - NOAA Federal
<chris.barker@noaa.gov> wrote:
> On Thu, Apr 4, 2013 at 11:26 AM, <josef.pktd@gmail.com> wrote:
>>> Before you answer that -- does anyone see a use case for the 'A' and
>>> 'K' flags that can't be reasonably easily accomplished with .view() or
>>> asarray() or ???
>>
>> What order does a[a>2] use to create the returned 1-D array?
> ...
>> However, I never needed to know and never cared
>> a[a>2] = 5
>> a[a>2] = b[a>2]
>>
>> Now, after this thread, I know about "K",
>
> does that use case use ravel() or reshape() under the hood?
only ravel has "K" as far as I saw in the current documentation.
example for ravel("K") would be if axis=None in functions and we
only have elementwise or reduce operations.
All the code I've seen uses just ravel() in this case, instead,
ravel("K") would have a better chance to avoid array copying,
if axis is None:
x = x.ravel("K")
return ((x - x.mean(0))**2).sum(0)
but it's dangerous because, if there is a second array, it might not ravel("K")
the same way
x.ravel("K") - y.ravel("K") sounds fun
similar if x[mask] wouldn't select a fixed "order", then
a[a>2] = b[a>2] would also be fun
fun := find the bug that I have hidden in this code
The only reason to use reshape with "A", I can think
of, is, if the array (matrix) is symmetric, or if it's a square
picture and we never care whether it's upright or sideways.
reshape(.., order="A") and ravel("A") should roundtrip, I guess.
Josef
>
>> and there might be cases
>> where it would be appropriate to minimize copying memory,
>
> hmm -- yes, that makes sense, and perhaps compelling enough to keep
> them around (at least with perhaps better docs).
>
> -Chris
>
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R (206) 526-6959 voice
> 7600 Sand Point Way NE (206) 526-6329 fax
> Seattle, WA 98115 (206) 526-6317 main reception
>
> Chris.Barker@noaa.gov
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
More information about the NumPy-Discussion
mailing list