Re: [Numpy-discussion] Contribution

2011-05-29 Thread Gael Varoquaux
On Sun, May 29, 2011 at 07:09:42AM +0400, Dmitriy Rybalkin wrote:
 Thank you, Gael, I really hope that I'll improve my programming skills.
 Also I have a question: Will the page with my example be deleted in
 case the code is not efficient or smth else has been found to be
 wrong?

I cannot really answer this question, as there is no rule: it depends on
the goodwill of whoever reads and tries out the page. It's a wiki. In my
experience, people are reluctant to delete other's work. Sometimes they
fix it, which is the best solution.

Gael

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


Re: [Numpy-discussion] finding elements that match any in a set

2011-05-29 Thread Alan G Isaac
On 5/28/2011 3:40 PM, Robert wrote:
 (myarray in mylist) turns into mylist.__contains__(myarray).
 Only the list object is ever checked for this method. There is no
 paired method myarray.__rcontains__(mylist) so there is nothing that
 numpy can override to make this operation do anything different from
 what lists normally do, which is check if the given object is equal to
 one of the items in the list.


This seems to me to slightly miscast the problem.
How would an __rcontains__ method really fix things?
Would the list type check against a table of stuff
that it knows how to contain?  That seems horrible.
And even if possible, NumPy would then have to break
the rule that ``in`` tests for equality,
because (I believe) the real problem in this case
is that np equality testing
does not return a bool.  From this perspective,
what is missing is not __rcontains__ (since the list
already knows what to do) but rather __eeq__ for
element-by-element comparison (ideally, along with an
element-by-element operator such as say .==).

In the meantime the OP could use
any(all(a==x) for x in lst)

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


Re: [Numpy-discussion] finding elements that match any in a set

2011-05-29 Thread Alan G Isaac
On 5/28/2011 3:46 PM, Robert Kern wrote:
 mylist.__contains__(x), it should treat all objects exactly
 the same: check if it equals any item that it contains. There is no
 way for it to say, Oh, I don't know how to deal with this type, so
 I'll pass it over to x.__contains__().


Which makes my comment redundant ...
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] finding elements that match any in a set

2011-05-29 Thread Neil Crighton
Michael Katz michaeladamkatz at yahoo.com writes:

 Yes, thanks, np.in1d is what I needed. I didn't know how to find that.

Did you check in the documentation? If so, where did you check? Would you have
found it if it was in the 'See also' section of where()?

(http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html)

I ask because people often post to the list needing in1d() after not being 
able to find it via the docs, so it would be nice to add references in
the places people go looking for it.

Neil


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


Re: [Numpy-discussion] AttributeError in numpy.distutils

2011-05-29 Thread Ralf Gommers
On Sun, May 22, 2011 at 8:14 PM, Branimir Sesar bse...@astro.caltech.eduwrote:

 On 05/22/2011 04:17 AM, Ralf Gommers wrote:
 
 
  On Thu, May 19, 2011 at 8:28 PM, Branimir Sesar
  bse...@astro.caltech.edu mailto:bse...@astro.caltech.edu wrote:
 
  Dear Numpy users,
 
  I've encountered an AttributeError in numpy.distutils
 
 File
 
 /home/bsesar/usr/pydebug/lib/python2.7/site-packages/numpy/distutils/command/build_src.py,
  line 646, in swig_sources
   extension.swig_opts.remove('-c++')
  AttributeError: 'str' object has no attribute 'remove'
 
  while compiling some code with Python 2.7.1 and Numpy 1.6.0.
 
 
  What are you doing here, compiling numpy? Building some of your own
  swig-ed code? Please give the details needed to reproduce your issue.

 I've been trying to compile Scikits ANN
 (http://projects.scipy.org/scikits/wiki/AnnWrapper) with Python 2.7.1,
 numpy 1.6.0, and SWIG 2.0.3 but the compilation breaks down down with
 the error given below. Previously, I was able to compile Scikits ANN
 using Enthought Python Distribution 7.0.2 (Python 2.7.1, numpy 1.5.1,
 swig 1.3.40).

 running install
 running bdist_egg
 running egg_info
 running build_src
 build_src
 building extension scikits.ann._ANN sources
 Traceback (most recent call last):
File setup.py, line 139, in module
  test_suite = 'nose.collector',
File

 /home/bsesar/usr/pydebug/lib/python2.7/site-packages/numpy/distutils/core.py,

 line 186, in setup
  return old_setup(**new_attr)
File /home/bsesar/usr/pydebug/lib/python2.7/distutils/core.py, line
 152, in setup
  dist.run_commands()
File /home/bsesar/usr/pydebug/lib/python2.7/distutils/dist.py, line
 953, in run_commands
  self.run_command(cmd)
File /home/bsesar/usr/pydebug/lib/python2.7/distutils/dist.py, line
 972, in run_command
  cmd_obj.run()
File

 /home/bsesar/usr/pydebug/lib/python2.7/site-packages/numpy/distutils/command/install.py,

 line 57, in run
  r = self.setuptools_run()
File

 /home/bsesar/usr/pydebug/lib/python2.7/site-packages/numpy/distutils/command/install.py,

 line 51, in setuptools_run
  self.do_egg_install()
File build/bdist.linux-x86_64/egg/setuptools/command/install.py,
 line 96, in do_egg_install
File /home/bsesar/usr/pydebug/lib/python2.7/distutils/cmd.py, line
 326, in run_command
  self.distribution.run_command(command)
File /home/bsesar/usr/pydebug/lib/python2.7/distutils/dist.py, line
 972, in run_command
  cmd_obj.run()
File build/bdist.linux-x86_64/egg/setuptools/command/bdist_egg.py,
 line 167, in run
File /home/bsesar/usr/pydebug/lib/python2.7/distutils/cmd.py, line
 326, in run_command
  self.distribution.run_command(command)
File /home/bsesar/usr/pydebug/lib/python2.7/distutils/dist.py, line
 972, in run_command
  cmd_obj.run()
File

 /home/bsesar/usr/pydebug/lib/python2.7/site-packages/numpy/distutils/command/egg_info.py,

 line 8, in run
  self.run_command(build_src)
File /home/bsesar/usr/pydebug/lib/python2.7/distutils/cmd.py, line
 326, in run_command
  self.distribution.run_command(command)
File /home/bsesar/usr/pydebug/lib/python2.7/distutils/dist.py, line
 972, in run_command
  cmd_obj.run()
 File

 /home/bsesar/usr/pydebug/lib/python2.7/site-packages/numpy/distutils/command/build_src.py,

 line 152, in run
  self.build_sources()
 File

 /home/bsesar/usr/pydebug/lib/python2.7/site-packages/numpy/distutils/command/build_src.py,

 line 169, in build_sources
  self.build_extension_sources(ext)
 File

 /home/bsesar/usr/pydebug/lib/python2.7/site-packages/numpy/distutils/command/build_src.py,

 line 332, in build_extension_sources
  sources = self.swig_sources(sources, ext)
 File

 /home/bsesar/usr/pydebug/lib/python2.7/site-packages/numpy/distutils/command/build_src.py,

 line 646, in swig_sources
  extension.swig_opts.remove('-c++')
 AttributeError: 'str' object has no attribute 'remove'

 Looks like this is a bug introduced in numpy 1.6.0 by commit ff0822c4.

Right above this line (numpy/distutils/command/build_src.py, line 646) add
this:

if isinstance(extension.swig_opts, basestring):
extension.swig_opts = extension.swig_opts.split()

Then you should be able to compile scikits.ann.

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


Re: [Numpy-discussion] finding elements that match any in a set

2011-05-29 Thread Chris Barker
 On 5/28/2011 3:40 PM, Robert wrote:
 (myarray in mylist) turns into mylist.__contains__(myarray).
 Only the list object is ever checked for this method. There is no
 paired method myarray.__rcontains__(mylist) so there is nothing that
 numpy can override to make this operation do anything different from
 what lists normally do,

however, numpy arrays should be able to override in be defining their 
own.__contains__ method, so you could do:

something in an_array

and get a useful, vectorized result.

So I thought I'd see what currently happens when I try that:

In [24]: a
Out[24]: array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])

In [25]: 3 in a
Out[25]: True

So the simple case works just like a list. But what If I want what the 
OP wants:

In [26]: b
Out[26]: array([3, 6, 4])

In [27]: b in a
Out[27]: False

OK, so the full b array is not in a, and it doesn't vectorize it, 
either. But:

In [29]: a
Out[29]:
array([[ 0,  1,  2],
[ 3,  4,  5],
[ 6,  7,  8],
[ 9, 10, 11]])

In [30]: b in a
Out[30]: True

HUH?

I'm not sure by what definition we would say that b is contained in a.

but maybe..

In [41]: b
Out[41]: array([  4,   2, 345])

In [42]: b in a
Out[42]: False

so it's are all of the elements in b in a somewhere? but only for 2-d 
arrays?


So what does it mean?

The docstring is not helpful:

In [58]: np.ndarray.__contains__?
Type:   wrapper_descriptor
Base Class: type 'wrapper_descriptor'
String Form:slot wrapper '__contains__' of 'numpy.ndarray' objects
Namespace:  Interactive
Docstring:
 x.__contains__(y) == y in x


If nothing useful, maybe it could provide a vectorized version of in 
for this sort of use case.

-Chris






-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/ORR(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

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


Re: [Numpy-discussion] finding elements that match any in a set

2011-05-29 Thread Michael Katz
Yes, in this case I definitely would have found in1d() if it was referenced in 
the where() section, either as a see also or even better as an example where 
where() is combined with np.in1d():


indexes_of_interest = np.where( np.in1d( my_records.integer_field, 
my_values_of_interest ) )

I think the where() documentation page must be a place where a lot of 
people/newbies spend a lot of time. Perhaps like me they are focusing on the 
solution being where() + some python stuff I already know, instead of 
thinking 
of other numpy functions, like in1d(), that might come into play.

It makes sense that in1d() is under the Set section. However (just to try to 
explain further why I didn't look and find it there), somehow I think of set 
when I am focused on having a list without duplicates. In my case I wasn't 
worried about duplicates, just about I want all the guys that match any of 
these other guys. I did google for numpy member, numpy membership, numpy 
in, but none led me to in1d().

Also, it's worth saying that, as a newcomer to numpy and relative newcomer to 
python, I often think that what I'm looking for isn't going to end up being a 
function with a name -- often some use of slices or (fancy) indexing, or some 
other pure syntax mechanism, ends up doing what you want. So that's one 
reason 
I didn't simply scan all the available numpy function names.




From: Neil Crighton neilcrigh...@gmail.com
To: numpy-discussion@scipy.org
Sent: Sun, May 29, 2011 10:03:25 AM
Subject: Re: [Numpy-discussion] finding elements that match any in a set

Michael Katz michaeladamkatz at yahoo.com writes:

 Yes, thanks, np.in1d is what I needed. I didn't know how to find that.

Did you check in the documentation? If so, where did you check? Would you have
found it if it was in the 'See also' section of where()?

(http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html)

I ask because people often post to the list needing in1d() after not being 
able to find it via the docs, so it would be nice to add references in
the places people go looking for it.

Neil


___
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


Re: [Numpy-discussion] finding elements that match any in a set

2011-05-29 Thread eat
On Sun, May 29, 2011 at 10:58 PM, Chris Barker chris.bar...@noaa.govwrote:

  On 5/28/2011 3:40 PM, Robert wrote:
  (myarray in mylist) turns into mylist.__contains__(myarray).
  Only the list object is ever checked for this method. There is no
  paired method myarray.__rcontains__(mylist) so there is nothing that
  numpy can override to make this operation do anything different from
  what lists normally do,

 however, numpy arrays should be able to override in be defining their
 own.__contains__ method, so you could do:

 something in an_array

 and get a useful, vectorized result.

 So I thought I'd see what currently happens when I try that:

 In [24]: a
 Out[24]: array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])

 In [25]: 3 in a
 Out[25]: True

 So the simple case works just like a list. But what If I want what the
 OP wants:

 In [26]: b
 Out[26]: array([3, 6, 4])

 In [27]: b in a
 Out[27]: False

 OK, so the full b array is not in a, and it doesn't vectorize it,
 either. But:

 In [29]: a
 Out[29]:
 array([[ 0,  1,  2],
[ 3,  4,  5],
[ 6,  7,  8],
[ 9, 10, 11]])

 In [30]: b in a
 Out[30]: True

 HUH?

 I'm not sure by what definition we would say that b is contained in a.

 but maybe..

 In [41]: b
 Out[41]: array([  4,   2, 345])

 In [42]: b in a
 Out[42]: False

 so it's are all of the elements in b in a somewhere? but only for 2-d
 arrays?


 So what does it mean?

FWIW, a short prelude on the theme seems quite promising, indeed:
In []: A
Out[]:
array([[0, 1, 2],
   [3, 4, 5],
   [6, 7, 8]])
In []: [0, 1, 2] in A
Out[]: True
In []: [0, 3, 6] in A
Out[]: True
In []: [0, 4, 8] in A
Out[]: True
In []: [8, 4, 0] in A
Out[]: True
In []: [2, 4, 6] in A
Out[]: True
In []: [6, 4, 2] in A
Out[]: True
In []: [3, 1, 5] in A
Out[]: True
In [1061]: [3, 1, 4] in A
Out[1061]: True
But
In []: [1, 2, 3] in A
Out[]: False
In []: [3, 2, 1] in A
Out[]: True

So, obviously the logic behind __contains__ is not so very straightforward.
Perhaps just a bug?

Regards,
eat


 The docstring is not helpful:

 In [58]: np.ndarray.__contains__?
 Type:   wrapper_descriptor
 Base Class: type 'wrapper_descriptor'
 String Form:slot wrapper '__contains__' of 'numpy.ndarray' objects
 Namespace:  Interactive
 Docstring:
 x.__contains__(y) == y in x


 If nothing useful, maybe it could provide a vectorized version of in
 for this sort of use case.

 -Chris






 --
 Christopher Barker, Ph.D.
 Oceanographer

 Emergency Response Division
 NOAA/NOS/ORR(206) 526-6959   voice
 7600 Sand Point Way NE   (206) 526-6329   fax
 Seattle, WA  98115   (206) 526-6317   main reception

 chris.bar...@noaa.gov
 ___
 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