[Numpy-tickets] [NumPy] #402: newaxis incompatible with array indexing

NumPy numpy-tickets at scipy.net
Sat Dec 16 16:59:25 CST 2006


#402: newaxis incompatible with array indexing
--------------------------+-------------------------------------------------
 Reporter:  NeilenMarais  |       Owner:  somebody
     Type:  defect        |      Status:  new     
 Priority:  normal        |   Milestone:          
Component:  Other         |     Version:          
 Severity:  normal        |    Keywords:          
--------------------------+-------------------------------------------------
 Hi.

 I get the following:

 {{{
 import numpy as N
 dofs = N.arange(5)+1
 physVals = N.ones((5,4,3))
 ....
 In [35]: physVals[0:3]*dofs[[4,3,2], N.newaxis, N.newaxis]
 ---------------------------------------------------------------------------
 exceptions.TypeError                                 Traceback (most
 recent call last)

 /home/brick/akademie/NewCode/working/<ipython console>

 TypeError: an integer is required
 }}}

 I can get the intended result like this:

 {{{
 In [36]: physVals[0:3]*dofs[[4,3,2]][:, N.newaxis, N.newaxis]
 Out[36]:
 array([[[ 5.,  5.,  5.],
         [ 5.,  5.,  5.],
         [ 5.,  5.,  5.],
         [ 5.,  5.,  5.]],

        [[ 4.,  4.,  4.],
         [ 4.,  4.,  4.],
         [ 4.,  4.,  4.],
         [ 4.,  4.,  4.]],

        [[ 3.,  3.,  3.],
         [ 3.,  3.,  3.],
         [ 3.,  3.,  3.],
         [ 3.,  3.,  3.]]])
 }}}

-- 
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/402>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.


More information about the Numpy-tickets mailing list