Re: [Numpy-discussion] Installing numpy with MKL

2010-08-05 Thread David Warde-Farley

On 2010-08-05, at 4:53 PM, Søren Gammelmark wrote:

> It seems to me, that you are using an libiomp5 for Intel Itanium 
> (lib/intel64) or such, but an MKL for EM64T-processors (lib/em64t). In 
> my case I used EM64T in all cases (I'm running AMD Opteron) . I don't 
> think the two types of libraries are compatible, but I might be wrong.

I don't think lib/intel64 implies Itanium. Indeed, running 'file' on it yields

libiomp5.so: ELF 64-bit LSB shared object, AMD x86-64, version 1 (SYSV), not 
stripped

I found this very helpful blog post: 
http://marklodato.github.com/2009/08/30/numpy-scipy-and-intel.html which seems 
to get NumPy built for me on the cluster. The key seemed to be changing the 
'icc' executable and also explicitly selecting the mkl_mc (or in my case mc3) 
library to link.

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


Re: [Numpy-discussion] ANN: NumPy 1.5.0 beta 1

2010-08-05 Thread David Warde-Farley

On 2010-08-01, at 12:38 PM, Ralf Gommers wrote:

> I am pleased to announce the availability of the first beta of NumPy 1.5.0. 
> This will be the first NumPy release to include support for Python 3, as well 
> as for Python 2.7. Please try this beta and report any problems on the NumPy 
> mailing list.
> 
> Binaries, sources and release notes can be found at
> https://sourceforge.net/projects/numpy/files/
> Please note that binaries for Python 3.1 are not yet up, they will follow as 
> soon as a minor issue with building them is resolved. Building from source 
> with Python 3.1 should work without problems.

Hey Ralf,

I am getting a single test failure:

==
FAIL: test_special_values (test_umath_complex.TestClog)
--
Traceback (most recent call last):
  File 
"/home/dwf/pkg/lib/python2.7/site-packages/numpy/core/tests/test_umath_complex.py",
 line 275, in test_special_values
assert_almost_equal(np.log(np.conj(xa[i])), np.conj(np.log(xa[i])))
  File "/home/dwf/pkg/lib/python2.7/site-packages/numpy/testing/utils.py", line 
443, in assert_almost_equal
raise AssertionError(msg)
AssertionError: 
Arrays are not almost equal
 ACTUAL: array([-inf+3.14159265j])
 DESIRED: array([-inf-3.14159265j])
>>  raise AssertionError('\nArrays are not almost equal\n ACTUAL: 
>> array([-inf+3.14159265j])\n DESIRED: array([-inf-3.14159265j])')

This is on a Xeon E5540 built against the MKL 11.1, if that matters (I suspect 
it doesn't).

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


Re: [Numpy-discussion] Installing numpy with MKL

2010-08-05 Thread Matthieu Brucher
> I've been having a similar problem compiling NumPy with MKL on a cluster with 
> a site-wide license. Dag's site.cfg fails to config if I use 'iomp5' in it, 
> since (at least with this version, 11.1) libiomp5 is located in
>
>        /scinet/gpc/intel/Compiler/11.1/072/lib/intel64/
>
> whereas the actual proper MKL
>
>        /scinet/gpc/intel/Compiler/11.1/072/mkl/lib/em64t/
>
> I've tried putting both in my library_dirs separated by a colon as is 
> suggested by the docs, but python setup.py config fails to find MKL in this 
> case. Has anyone else run into this issue?

Indeed, this is a issue I also faced. I had to copy all the libs in
one folder. If one has only MKL, iomp5 is provided (as well as guide
IIRC), but with the Compiler pack, they are not in the MKL lib folder.

Matthieu
-- 
Information System Engineer, Ph.D.
Blog: http://matt.eifelle.com
LinkedIn: http://www.linkedin.com/in/matthieubrucher
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] use index array of len n to select columns of n x m array

2010-08-05 Thread John Salvatier
choose might be slower if you weren't doing an "arange(N)" each time.

On Thu, Aug 5, 2010 at 1:51 PM, Keith Goodman  wrote:

> On Thu, Aug 5, 2010 at 1:32 PM,   wrote:
> > On Thu, Aug 5, 2010 at 4:07 PM, Martin Spacek 
> wrote:
> >> josef.pkt wrote:
> > a = np.array([[0, 1],
> >>   [2, 3],
> >>   [4, 5],
> >>   [6, 7],
> >>   [8, 9]])
> > i = np.array([0, 1, 1, 0, 1])
> > a[range(a.shape[0]), i]
> >> array([0, 3, 5, 6, 9])
> > a[np.arange(a.shape[0]), i]
> >> array([0, 3, 5, 6, 9])
> >>
> >>
> >> Thanks for all the tips. I guess I was hoping for something that could
> avoid
> >> having to generate np.arange(a.shape[0]), but
> >>
> >>  >>> a[np.arange(a.shape[0]), i]
> >>
> >> sure is easy to understand. Is there maybe a more CPU and/or memory
> efficient
> >> way? I kind of like John Salvatier's idea:
> >>
> >>  >>> np.choose(i, (a[:,0], a[:,1])
> >>
> >> but that would need to be generalized to "a" of arbitrary columns.
> >
> > seems to work:
> >
>  np.choose(i, a.T)
> > array([0, 3, 5, 6, 9])
> >
> > but wouldn't get around the 31 limit that you found.
>
> Choose is fast:
>
> >> N = 1000
> >> a = np.random.randint(0, 9, (N,2))
> >> i = np.random.randint(0, 2, N)
> >> timeit a[range(N), i]
> 1 loops, best of 3: 108 us per loop
> >> timeit a[np.arange(N), i]
> 1 loops, best of 3: 39 us per loop
> >> timeit np.choose(i, a.T)
> 1 loops, best of 3: 32.3 us per loop
>
> But flat is faster:
>
> >> timeit idx = np.arange(N); idx *= 2; idx += i; a.flat[idx]
> 10 loops, best of 3: 16.8 us per loop
> ___
> 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] {OT} Mailing trends

2010-08-05 Thread josef . pktd
On Thu, Aug 5, 2010 at 3:43 PM, Gökhan Sever  wrote:
> Hello,
> There is a nice e-mailing trend tool for Gmail users
> at http://code.google.com/p/mail-trends/
> It is a command line tool producing an html output showing your e-mailing
> statistics. In my inbox, the following threads are highly ranked in the top
> threads section.
>
> [Numpy-discussion] Announcing toydist, improving distribution and packaging
> situation
> [SciPy-Dev] scipy.stats
> [Numpy-discussion] curious about how people would feel about moving to
> github
>
> Just out of curiosity, are there any mailing trends (top threads, top
> posters, etc...) provided for the Python related mailing archives?
> Share your comments please.

I only know the top poster statistics for googlegroups

http://groups.google.ca/group/scipy-user/about?hl=en

but numpy-discussion and scipy-dev are not on google groups

Josef


> --
> Gökhan
>
> ___
> 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] Installing numpy with MKL

2010-08-05 Thread Søren Gammelmark
It seems to me, that you are using an libiomp5 for Intel Itanium 
(lib/intel64) or such, but an MKL for EM64T-processors (lib/em64t). In 
my case I used EM64T in all cases (I'm running AMD Opteron) . I don't 
think the two types of libraries are compatible, but I might be wrong.

/Søren


On 05-08-2010 21:06, David Warde-Farley wrote:
> On 2010-08-04, at 2:18 AM, Matthieu Brucher wrote:
>
>
>> 2010/8/4 Søren Gammelmark:
>>  
>>>
 I wouldn't know for sure, but could this be related to changes to the
 gcc compiler in Fedora 13 (with respect to implicit DSO linking) or
 would that only be an issue at build-time?

 http://fedoraproject.org/w/index.php?title=UnderstandingDSOLinkChange
  
>>> I'm not entirely sure I understand the link, but if it has anything to
>>> do with the compiler it seems to me that it should be the Intel
>>> compiler. The python I use is compiled with GCC but everything in numpy
>>> is done with the Intel compilers. Shouldn't it then be something with
>>> the Intel compilers?
>>>
>>> /Søren
>>>
>> Unfortunately, I think you'll ahve to use Dag's patch. MKL has a
>> specific loading procedure since a few releases, you have to abide by
>> it.
>>  
> I've been having a similar problem compiling NumPy with MKL on a cluster with 
> a site-wide license. Dag's site.cfg fails to config if I use 'iomp5' in it, 
> since (at least with this version, 11.1) libiomp5 is located in
>
>   /scinet/gpc/intel/Compiler/11.1/072/lib/intel64/
>
> whereas the actual proper MKL
>
>   /scinet/gpc/intel/Compiler/11.1/072/mkl/lib/em64t/
>
> I've tried putting both in my library_dirs separated by a colon as is 
> suggested by the docs, but python setup.py config fails to find MKL in this 
> case. Has anyone else run into this issue?
>
> David
> ___
> 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] use index array of len n to select columns of n x m array

2010-08-05 Thread Keith Goodman
On Thu, Aug 5, 2010 at 1:32 PM,   wrote:
> On Thu, Aug 5, 2010 at 4:07 PM, Martin Spacek  wrote:
>> josef.pkt wrote:
> a = np.array([[0, 1],
>>                   [2, 3],
>>                   [4, 5],
>>                   [6, 7],
>>                   [8, 9]])
> i = np.array([0, 1, 1, 0, 1])
> a[range(a.shape[0]), i]
>> array([0, 3, 5, 6, 9])
> a[np.arange(a.shape[0]), i]
>> array([0, 3, 5, 6, 9])
>>
>>
>> Thanks for all the tips. I guess I was hoping for something that could avoid
>> having to generate np.arange(a.shape[0]), but
>>
>>  >>> a[np.arange(a.shape[0]), i]
>>
>> sure is easy to understand. Is there maybe a more CPU and/or memory efficient
>> way? I kind of like John Salvatier's idea:
>>
>>  >>> np.choose(i, (a[:,0], a[:,1])
>>
>> but that would need to be generalized to "a" of arbitrary columns.
>
> seems to work:
>
 np.choose(i, a.T)
> array([0, 3, 5, 6, 9])
>
> but wouldn't get around the 31 limit that you found.

Choose is fast:

>> N = 1000
>> a = np.random.randint(0, 9, (N,2))
>> i = np.random.randint(0, 2, N)
>> timeit a[range(N), i]
1 loops, best of 3: 108 us per loop
>> timeit a[np.arange(N), i]
1 loops, best of 3: 39 us per loop
>> timeit np.choose(i, a.T)
1 loops, best of 3: 32.3 us per loop

But flat is faster:

>> timeit idx = np.arange(N); idx *= 2; idx += i; a.flat[idx]
10 loops, best of 3: 16.8 us per loop
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] use index array of len n to select columns of n x m array

2010-08-05 Thread Bruce Southey
  On 08/05/2010 03:07 PM, Martin Spacek wrote:
> josef.pkt wrote:
 a = np.array([[0, 1],
> [2, 3],
> [4, 5],
> [6, 7],
> [8, 9]])
 i = np.array([0, 1, 1, 0, 1])
 a[range(a.shape[0]), i]
> array([0, 3, 5, 6, 9])
 a[np.arange(a.shape[0]), i]
> array([0, 3, 5, 6, 9])
>
>
> Thanks for all the tips. I guess I was hoping for something that could avoid
> having to generate np.arange(a.shape[0]), but
>
>   >>>  a[np.arange(a.shape[0]), i]
>
> sure is easy to understand. Is there maybe a more CPU and/or memory efficient
> way? I kind of like John Salvatier's idea:
>
>   >>>  np.choose(i, (a[:,0], a[:,1])
>
> but that would need to be generalized to "a" of arbitrary columns. This could 
> be
> done using split or vsplit:
>
>   >>>  np.choose(i, np.vsplit(a.T, a.shape[1]))[0]
> array([0, 3, 5, 6, 9])
>
> That avoids having to generate an np.arange(), but looks kind of wordy. Is 
> there
> a more compact way? Maybe this is better:
>
>   >>>  b, = i.choose(np.vsplit(a.T, a.shape[1]))
>   >>>  b
> array([0, 3, 5, 6, 9])
>
> Ah, but I've just discovered a strange limitation of choose():
>
>   >>>  a = np.arange(9*32)
>   >>>  a.shape = 9, 32
>   >>>  i = np.random.randint(0, a.shape[1], size=a.shape[0])
>   >>>  i
> array([ 1, 21, 23,  2, 30, 23, 20, 30, 17])
>   >>>  b, = i.choose(np.vsplit(a.T, a.shape[1]))
> Traceback (most recent call last):
> File "", line 1, in
> ValueError: Need between 2 and (32) array objects (inclusive).
>
> Compare with:
>
>   >>>  a = np.arange(9*31)
>   >>>  a.shape = 9, 31
>   >>>  i = np.random.randint(0, a.shape[1], size=a.shape[0])
>   >>>  i
> array([14, 22, 18,  6,  1, 12,  8,  8, 30])
>   >>>  b, = i.choose(np.vsplit(a.T, a.shape[1]))
>   >>>  b
> array([ 14,  53,  80,  99, 125, 167, 194, 225, 278])
>
> So, the ValueError should really read "Need between 2 and 31 array object
> (inclusive)", should it not? Also, I can't seem to find this limitation in the
> docs for choose(). I guess I'll stick to using the np.arange(a.shape[0]) 
> method.
>
> Martin
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

I think you might want numpy's where function:
 >>> np.where(i,a[:,1],a[:,0])
array([0, 3, 5, 6, 9])

Bruce



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


Re: [Numpy-discussion] use index array of len n to select columns of n x m array

2010-08-05 Thread josef . pktd
On Thu, Aug 5, 2010 at 4:07 PM, Martin Spacek  wrote:
> josef.pkt wrote:
 a = np.array([[0, 1],
>                   [2, 3],
>                   [4, 5],
>                   [6, 7],
>                   [8, 9]])
 i = np.array([0, 1, 1, 0, 1])
 a[range(a.shape[0]), i]
> array([0, 3, 5, 6, 9])
 a[np.arange(a.shape[0]), i]
> array([0, 3, 5, 6, 9])
>
>
> Thanks for all the tips. I guess I was hoping for something that could avoid
> having to generate np.arange(a.shape[0]), but
>
>  >>> a[np.arange(a.shape[0]), i]
>
> sure is easy to understand. Is there maybe a more CPU and/or memory efficient
> way? I kind of like John Salvatier's idea:
>
>  >>> np.choose(i, (a[:,0], a[:,1])
>
> but that would need to be generalized to "a" of arbitrary columns.

seems to work:

>>> np.choose(i, a.T)
array([0, 3, 5, 6, 9])

but wouldn't get around the 31 limit that you found.

Josef

 This could be
> done using split or vsplit:
>
>  >>> np.choose(i, np.vsplit(a.T, a.shape[1]))[0]
> array([0, 3, 5, 6, 9])
>
> That avoids having to generate an np.arange(), but looks kind of wordy. Is 
> there
> a more compact way? Maybe this is better:
>
>  >>> b, = i.choose(np.vsplit(a.T, a.shape[1]))
>  >>> b
> array([0, 3, 5, 6, 9])
>
> Ah, but I've just discovered a strange limitation of choose():
>
>  >>> a = np.arange(9*32)
>  >>> a.shape = 9, 32
>  >>> i = np.random.randint(0, a.shape[1], size=a.shape[0])
>  >>> i
> array([ 1, 21, 23,  2, 30, 23, 20, 30, 17])
>  >>> b, = i.choose(np.vsplit(a.T, a.shape[1]))
> Traceback (most recent call last):
>   File "", line 1, in 
> ValueError: Need between 2 and (32) array objects (inclusive).
>
> Compare with:
>
>  >>> a = np.arange(9*31)
>  >>> a.shape = 9, 31
>  >>> i = np.random.randint(0, a.shape[1], size=a.shape[0])
>  >>> i
> array([14, 22, 18,  6,  1, 12,  8,  8, 30])
>  >>> b, = i.choose(np.vsplit(a.T, a.shape[1]))
>  >>> b
> array([ 14,  53,  80,  99, 125, 167, 194, 225, 278])
>
> So, the ValueError should really read "Need between 2 and 31 array object
> (inclusive)", should it not? Also, I can't seem to find this limitation in the
> docs for choose(). I guess I'll stick to using the np.arange(a.shape[0]) 
> method.
>
> Martin
> ___
> 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] use index array of len n to select columns of n x m array

2010-08-05 Thread Martin Spacek
josef.pkt wrote:
>>> a = np.array([[0, 1],
   [2, 3],
   [4, 5],
   [6, 7],
   [8, 9]])
>>> i = np.array([0, 1, 1, 0, 1])
>>> a[range(a.shape[0]), i]
array([0, 3, 5, 6, 9])
>>> a[np.arange(a.shape[0]), i]
array([0, 3, 5, 6, 9])


Thanks for all the tips. I guess I was hoping for something that could avoid 
having to generate np.arange(a.shape[0]), but

 >>> a[np.arange(a.shape[0]), i]

sure is easy to understand. Is there maybe a more CPU and/or memory efficient 
way? I kind of like John Salvatier's idea:

 >>> np.choose(i, (a[:,0], a[:,1])

but that would need to be generalized to "a" of arbitrary columns. This could 
be 
done using split or vsplit:

 >>> np.choose(i, np.vsplit(a.T, a.shape[1]))[0]
array([0, 3, 5, 6, 9])

That avoids having to generate an np.arange(), but looks kind of wordy. Is 
there 
a more compact way? Maybe this is better:

 >>> b, = i.choose(np.vsplit(a.T, a.shape[1]))
 >>> b
array([0, 3, 5, 6, 9])

Ah, but I've just discovered a strange limitation of choose():

 >>> a = np.arange(9*32)
 >>> a.shape = 9, 32
 >>> i = np.random.randint(0, a.shape[1], size=a.shape[0])
 >>> i
array([ 1, 21, 23,  2, 30, 23, 20, 30, 17])
 >>> b, = i.choose(np.vsplit(a.T, a.shape[1]))
Traceback (most recent call last):
   File "", line 1, in 
ValueError: Need between 2 and (32) array objects (inclusive).

Compare with:

 >>> a = np.arange(9*31)
 >>> a.shape = 9, 31
 >>> i = np.random.randint(0, a.shape[1], size=a.shape[0])
 >>> i
array([14, 22, 18,  6,  1, 12,  8,  8, 30])
 >>> b, = i.choose(np.vsplit(a.T, a.shape[1]))
 >>> b
array([ 14,  53,  80,  99, 125, 167, 194, 225, 278])

So, the ValueError should really read "Need between 2 and 31 array object 
(inclusive)", should it not? Also, I can't seem to find this limitation in the 
docs for choose(). I guess I'll stick to using the np.arange(a.shape[0]) method.

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


[Numpy-discussion] {OT} Mailing trends

2010-08-05 Thread Gökhan Sever
Hello,

There is a nice e-mailing trend tool for Gmail users at
http://code.google.com/p/mail-trends/
It is a command line tool producing an html output showing your e-mailing
statistics. In my inbox, the following threads are highly ranked in the top
threads section.

[Numpy-discussion] Announcing toydist, improving distribution and packaging
situation
[SciPy-Dev] 
scipy.stats
[Numpy-discussion] curious about how people would feel about moving to
github

Just out of curiosity, are there any mailing trends (top threads, top
posters, etc...) provided for the Python related mailing archives?

Share your comments please.

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


Re: [Numpy-discussion] NumPy segfault when running tests (2.7, 1.4.1)

2010-08-05 Thread David Warde-Farley
On 2010-08-03, at 4:09 PM, Pauli Virtanen wrote:

> Tue, 03 Aug 2010 15:52:55 -0400, David Warde-Farley wrote:
> [clip]
>> in PyErr_WarnEx (category=0x11eb6c54,
>>text=0x5f90c0 "PyOS_ascii_strtod and PyOS_ascii_atof are deprecated.
>> Use PyOS_string_to_double instead.", stack_level=0) at
>>Python/_warnings.c:719
>> 719  res = do_warn(message, category, stack_level); 
>> (gdb)
> 
> That was probably fixed in r8394 in trunk.
> 
> But to be sure, can you supply the whole stack trace (type "bt" in the 
> gdb prompt).

Thanks Pauli, it does seem to be fixed in 1.5.0b1. I didn't get the memo 
somehow that 2.7 breaks NumPy 1.4.x.

Now I just have to chase down ugly MKL problems...

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


Re: [Numpy-discussion] Installing numpy with MKL

2010-08-05 Thread David Warde-Farley

On 2010-08-04, at 2:18 AM, Matthieu Brucher wrote:

> 2010/8/4 Søren Gammelmark :
>> 
>>> 
>>> I wouldn't know for sure, but could this be related to changes to the
>>> gcc compiler in Fedora 13 (with respect to implicit DSO linking) or
>>> would that only be an issue at build-time?
>>> 
>>> http://fedoraproject.org/w/index.php?title=UnderstandingDSOLinkChange
>> 
>> I'm not entirely sure I understand the link, but if it has anything to
>> do with the compiler it seems to me that it should be the Intel
>> compiler. The python I use is compiled with GCC but everything in numpy
>> is done with the Intel compilers. Shouldn't it then be something with
>> the Intel compilers?
>> 
>> /Søren
> 
> Unfortunately, I think you'll ahve to use Dag's patch. MKL has a
> specific loading procedure since a few releases, you have to abide by
> it.

I've been having a similar problem compiling NumPy with MKL on a cluster with a 
site-wide license. Dag's site.cfg fails to config if I use 'iomp5' in it, since 
(at least with this version, 11.1) libiomp5 is located in 

/scinet/gpc/intel/Compiler/11.1/072/lib/intel64/

whereas the actual proper MKL 

/scinet/gpc/intel/Compiler/11.1/072/mkl/lib/em64t/

I've tried putting both in my library_dirs separated by a colon as is suggested 
by the docs, but python setup.py config fails to find MKL in this case. Has 
anyone else run into this issue?

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


Re: [Numpy-discussion] use index array of len n to select columns of n x m array

2010-08-05 Thread John Salvatier
You may also use the choose function:

http://docs.scipy.org/doc/numpy/reference/generated/numpy.choose.html

choose(i, (a[:,0], a[:,1])

On Thu, Aug 5, 2010 at 10:31 AM, Keith Goodman  wrote:

> On Thu, Aug 5, 2010 at 10:26 AM,   wrote:
> > On Thu, Aug 5, 2010 at 1:12 PM, Martin Spacek 
> wrote:
> >> I want to take an n x m array "a" and index into it using an integer
> index array
> >> "i" of length n that will pull out the value at the designated column
> from each
> >> corresponding row of "a".
> >>
> > a = np.arange(10)
> > a.shape = 5, 2
> > a
> >> array([[0, 1],
> >>[2, 3],
> >>[4, 5],
> >>[6, 7],
> >>[8, 9]])
> > i = np.array([0, 1, 1, 0, 1])
> >>
> >> I want:
> >>
> > b = a.foo(i)
> > b
> >> array([0, 3, 5, 6, 9])
> >>
> >> What's foo? I can't get take() to do what I want. I went and wrote my
> own little
> >> Cython function to do this, but that seems silly (and is also array
> dtype
> >> dependent). I've tried reading through the numpy book, and I'm sure this
> is
> >> somewhere on the list, but I can't find it. I think it has something to
> do with
> >> fancy indexing. I should know how to do this by know...
> >
> > like this ?
>
> Yes, I like it. Textbook case of fancy indexing.
>
> >
>  a= np.array([[0, 1],
> >   [2, 3],
> >   [4, 5],
> >   [6, 7],
> >   [8, 9]])
>  i = np.array([0, 1, 1, 0, 1])
>  a[range(a.shape[0]), i]
> > array([0, 3, 5, 6, 9])
>  a[np.arange(a.shape[0]), i]
> > array([0, 3, 5, 6, 9])
> >
> > Josef
> >
> >>
> >> Cheers,
> >>
> >> Martin
> >>
> >> ___
> >> 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


Re: [Numpy-discussion] use index array of len n to select columns of n x m array

2010-08-05 Thread Keith Goodman
On Thu, Aug 5, 2010 at 10:26 AM,   wrote:
> On Thu, Aug 5, 2010 at 1:12 PM, Martin Spacek  wrote:
>> I want to take an n x m array "a" and index into it using an integer index 
>> array
>> "i" of length n that will pull out the value at the designated column from 
>> each
>> corresponding row of "a".
>>
> a = np.arange(10)
> a.shape = 5, 2
> a
>> array([[0, 1],
>>        [2, 3],
>>        [4, 5],
>>        [6, 7],
>>        [8, 9]])
> i = np.array([0, 1, 1, 0, 1])
>>
>> I want:
>>
> b = a.foo(i)
> b
>> array([0, 3, 5, 6, 9])
>>
>> What's foo? I can't get take() to do what I want. I went and wrote my own 
>> little
>> Cython function to do this, but that seems silly (and is also array dtype
>> dependent). I've tried reading through the numpy book, and I'm sure this is
>> somewhere on the list, but I can't find it. I think it has something to do 
>> with
>> fancy indexing. I should know how to do this by know...
>
> like this ?

Yes, I like it. Textbook case of fancy indexing.

>
 a= np.array([[0, 1],
>       [2, 3],
>       [4, 5],
>       [6, 7],
>       [8, 9]])
 i = np.array([0, 1, 1, 0, 1])
 a[range(a.shape[0]), i]
> array([0, 3, 5, 6, 9])
 a[np.arange(a.shape[0]), i]
> array([0, 3, 5, 6, 9])
>
> Josef
>
>>
>> Cheers,
>>
>> Martin
>>
>> ___
>> 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


Re: [Numpy-discussion] use index array of len n to select columns of n x m array

2010-08-05 Thread Keith Goodman
On Thu, Aug 5, 2010 at 10:12 AM, Martin Spacek  wrote:
> I want to take an n x m array "a" and index into it using an integer index 
> array
> "i" of length n that will pull out the value at the designated column from 
> each
> corresponding row of "a".
>
 a = np.arange(10)
 a.shape = 5, 2
 a
> array([[0, 1],
>        [2, 3],
>        [4, 5],
>        [6, 7],
>        [8, 9]])
 i = np.array([0, 1, 1, 0, 1])
>
> I want:
>
 b = a.foo(i)
 b
> array([0, 3, 5, 6, 9])

Here's one way:

>> a.flat[i + a.shape[1] * np.arange(a.shape[0])]
   array([0, 3, 5, 6, 9])
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] use index array of len n to select columns of n x m array

2010-08-05 Thread josef . pktd
On Thu, Aug 5, 2010 at 1:12 PM, Martin Spacek  wrote:
> I want to take an n x m array "a" and index into it using an integer index 
> array
> "i" of length n that will pull out the value at the designated column from 
> each
> corresponding row of "a".
>
 a = np.arange(10)
 a.shape = 5, 2
 a
> array([[0, 1],
>        [2, 3],
>        [4, 5],
>        [6, 7],
>        [8, 9]])
 i = np.array([0, 1, 1, 0, 1])
>
> I want:
>
 b = a.foo(i)
 b
> array([0, 3, 5, 6, 9])
>
> What's foo? I can't get take() to do what I want. I went and wrote my own 
> little
> Cython function to do this, but that seems silly (and is also array dtype
> dependent). I've tried reading through the numpy book, and I'm sure this is
> somewhere on the list, but I can't find it. I think it has something to do 
> with
> fancy indexing. I should know how to do this by know...

like this ?

>>> a= np.array([[0, 1],
   [2, 3],
   [4, 5],
   [6, 7],
   [8, 9]])
>>> i = np.array([0, 1, 1, 0, 1])
>>> a[range(a.shape[0]), i]
array([0, 3, 5, 6, 9])
>>> a[np.arange(a.shape[0]), i]
array([0, 3, 5, 6, 9])

Josef

>
> Cheers,
>
> Martin
>
> ___
> 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] use index array of len n to select columns of n x m array

2010-08-05 Thread Martin Spacek
I want to take an n x m array "a" and index into it using an integer index 
array 
"i" of length n that will pull out the value at the designated column from each 
corresponding row of "a".

>>> a = np.arange(10)
>>> a.shape = 5, 2
>>> a
array([[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]])
>>> i = np.array([0, 1, 1, 0, 1])

I want:

>>> b = a.foo(i)
>>> b
array([0, 3, 5, 6, 9])

What's foo? I can't get take() to do what I want. I went and wrote my own 
little 
Cython function to do this, but that seems silly (and is also array dtype 
dependent). I've tried reading through the numpy book, and I'm sure this is 
somewhere on the list, but I can't find it. I think it has something to do with 
fancy indexing. I should know how to do this by know...

Cheers,

Martin

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


Re: [Numpy-discussion] deprecations for 1.5

2010-08-05 Thread Pierre GM

On Aug 5, 2010, at 8:45 AM, Ralf Gommers wrote:

> Hi all,
> 
> I'm looking at what needs to be deprecated/removed and have a few questions:
> 
> 1. ma.core has some deprecations without version info:
>   make_mask: flag keyword 
>   MaskedArray.flag
>   MaskedArray.raw_data 
>   allclose: fillvalue keyword
>   Should these be removed, and if not can someone provide a version number 
> for when that does need to happen?


Yes, you can remove them, whenever you see fit.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] deprecations for 1.5

2010-08-05 Thread Ralf Gommers
Hi all,

I'm looking at what needs to be deprecated/removed and have a few questions:

1. ma.core has some deprecations without version info:
  make_mask: flag keyword
  MaskedArray.flag
  MaskedArray.raw_data
  allclose: fillvalue keyword
  Should these be removed, and if not can someone provide a version number
for when that does need to happen?

2. correlate: old_behavior keyword should be removed. Is it correct that
that means (besides changes in core/numeric.py) removing
multiarray.correlate code in multiarraymodule.c and renaming correlate2 to
correlate there?

3. Anything else that needs to be removed/deprecated besides what is noted
in the 1.4.0 release notes and ticket 1431?

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