Re: [Numpy-discussion] return type from ufuncs

2014-11-27 Thread Marek Wojciechowski
Dnia czwartek, 20 listopada 2014 18:47:41 Marek Wojciechowski pisze:
 Hi!
 
 I wrote a simple subclass of np.ndarray and now i do call np.sum() on it. I
 expected that the result will be a python float (or int) just like when
 summing up regular arrays. Instead i obtain the (scalar) view of my
 subclass. How can i change this behavior? I tried writing __array_wrap__
 method like this:
 
 def __array_wrap__(self, out_arr, context=None):
   selfv = self.view(np.ndarray)
 return np.ndarray.__array_wrap__(selfv, out_arr, context)
 
 but this just returns np.ndarray type and not float.

Hi!

I'm back with the problem of returning types form ndarray subclasses, now with 
ravelling the array. I wrote the __array_wrap__ function like this:

def __array_wrap__(self, out_arr, context=None):
arr = out_arr.view(np.ndarray)
if arr.ndim == 0:
arr = arr[()]
return arr

I was convinced that now ufuncs wil return always numpy arrays. But now i 
discovered that for example:

a.ravel()   

returns still the subclass type, not ndarray type. Ravel method apparently 
does not call __array_wrap__ (whereas np.ravel(a) does!). Is there a 
systematic way to resolve this or i need to write new ravel method?

Regards,
-- 
Marek Wojciechowski 


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Setting up a newcomers label on the issue tracker ?

2014-11-27 Thread Todd
KDE calls themjunior jobs.
On Nov 27, 2014 2:29 AM, Benjamin Root ben.r...@ou.edu wrote:

 FWIW, matplotlib calls it low hanging fruit. I think it is a better name
 than newcomers.

 On Wed, Nov 26, 2014 at 1:19 PM, Aldcroft, Thomas 
 aldcr...@head.cfa.harvard.edu wrote:



 On Wed, Nov 26, 2014 at 8:24 AM, Charles R Harris 
 charlesr.har...@gmail.com wrote:



 On Wed, Nov 26, 2014 at 2:36 AM, Sebastian Berg 
 sebast...@sipsolutions.net wrote:

 On Mi, 2014-11-26 at 08:44 +, David Cournapeau wrote:
  Hi,
 
 
  Would anybody mind if I create a label newcomers on GH, and start
  labelling simple issues ?

 We actually have an easy fix label, which I think had this in mind.
 However, I admit that I think some of these issues may not be easy at
 all (I guess it depends on what you consider easy ;)). In any case, I
 think just go ahead with creating a new label or reusing the current
 one. easy fix might be a starting point to find some candidate issues.

 - Sebsatian

 
 
  This is in anticipation to the bloomberg lab event in London this WE.
  I will try to give a hand to people interested in numpy/scipy,


 There is also a documentation label, and about 30 tickets with that
 label. That should be good for just practicing the mechanics.


 FWIW in astropy we settled on two properties, level of effort and level
 of sub-package expertise, with corresponding labels:

 - effort-low, effort-medium, and effort-high
 - package-novice, package-intermediate, package-expert

 This has been used with reasonable success.

 - Tom



 Chuck

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion



 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion



 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Finding values in an array

2014-11-27 Thread Alexander Belopolsky
I probably miss something very basic, but how given two arrays a and b, can
I find positions in a where elements of b are located?  If a were sorted, I
could use searchsorted, but I don't want to get valid positions for
elements that are not in a.  In my case, a has unique elements, but in the
general case I would accept the first match.  In other words, I am looking
for an array analog of list.index() method.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Finding values in an array

2014-11-27 Thread Stephan Hoyer
On Thu, Nov 27, 2014 at 10:15 PM, Alexander Belopolsky ndar...@mac.com
wrote:

 I probably miss something very basic, but how given two arrays a and b,
 can I find positions in a where elements of b are located?  If a were
 sorted, I could use searchsorted, but I don't want to get valid positions
 for elements that are not in a.  In my case, a has unique elements, but in
 the general case I would accept the first match.  In other words, I am
 looking for an array analog of list.index() method.


I don't know an easy solution to this problem in pure numpy, but if you
could do this pretty easily (and quite efficiently) if you are willing to
use pandas. Something like:

locs = pd.Index(a).get_indexer(b)

Note that -1 is used to denote a non-match, and get_indexer will raise if
the match is non-unique instead of returning the first element. If your
array is not 1d, you can still make this work but you'll need to use
np.ravel and np.unravel_index.

Actually, you may find that putting your data into pandas data structures
is a good solution, since pandas is designed to make exactly these sort of
alignment operations easy (and automatic).

I suppose the simplest solution to this problem would be to convert your
data into a list and use list.index() repeatedly (or you could even write
it yourself in a few lines), but I'd guess that was never implemented for
ndarrays because it's rather slow -- better to use a hash-table like a dict
or pandas.Index for repeated lookups.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion