[Numpy-discussion] Counting array elements
Russell E Owen
rowen at u.washington.edu
Fri Oct 22 15:19:02 EDT 2004
At 2:35 PM -0700 2004-10-22, Stephen Walton wrote:
>On Fri, 2004-10-22 at 11:17, Russell E Owen wrote about the sum() Ufunc
>vs. the sum() method:
>
>> Numarray is already confusing enough without identically
>> named functions and methods that do different things
>
>When I went through the Numarray docs and made suggestions for
>improvements (see the list I posted at Sourceforge), I didn't make any
>comments about functional changes, only what the documentation said.
>Since the sum() method is documented using 1-D arrays, you can't tell
>that it in fact behaves differently than the sum() Ufunc. On
>reflection, I also agree that the Ufuncs and methods should behave the
>same way.
>
>Why do you say 'numarray is confusing'? What in the docs would help
>un-confuse it, in your view?
OK, since I seem to be in a grumpy mood today, here are some examples
(probably nothing new here):
- I'll expose my ignorance, but I find the take stuff and fancy
indexing nearly incomprehensible. I've tried to follow the examples
(several times--i.e. every time I need to do something fancy), but
generally I either flail around until I find something that works, or
give up and write a C extension.
- I'd like to write C/C++ code that would work on multiple array
types. This seems a natural use of C++ templates, but that doesn't
seem to be "how it's done". I hate to think how the internal code is
managing this without being a horrible sphaghetti of code repeated
for each array type.
The nd_image package is the closest I've come to finding source code
that makes any sense to me in this areay. But it uses so many
custom-defined specialized functions that I figured it was just too
much work to figure out w/out a manual (and risky to rely on these
functions since they are internal to the package).
So I gave up and just support the one data type I really need now.
Very disappointing.
- Important functions are sometimes buried in a non-obvious (to me)
sub-package.
For example: try to find that location at which an array has a
minimum value (if there's more than one such point, pick any). You'd
think it'd be a standard numarray function, wouldn't you? After all,
you can ask for the minimum value. Now try to find it.
Well, I started out by trying to figure out how to get argmin to do
the job. Horrible.
Fortunately I finally found minimum_position buried in nd_image.
- Masked arrays are not integrated. Thus a lot of important filtering
and stuff simply cannot be done on masked data without writing custom
extensions. For instance I'd like to do a median-filter that ignores
masked data (taking the median of non-masked data only).
- For 2-d images x and y are reversed. I know this isn't going to
change, but it is a headache every time I have to write new image
processing code.
- I keep wanting more support for dealing with arrays of indices,
e.g. "give me all the indices for which this is true", then use that
to process the data in an array. Numarray seems to do that kind of
operation in an entirely different way, suggesting I'm not "with it"
on the underlying philosophy. Unfortunately no really good examples
come to mind at the moment (it's been awhile since I've created new
code using numarray), though I was fairly well convinced that if I
had enough support for this I could code an efficient radial profile
function w/out using a C extension.
-- Russell
More information about the NumPy-Discussion
mailing list