python - Passing list as slice for a N-dimensional numpy array -


I am trying to manipulate the value of the n-dimensional array based on the user's decision, on which the array Should go change. This example works fine:

  import np as np a = np.arange (24). Renewal (2,3,4) tochange = ['0', '0', '0'] #input via raw_input to a [toChange] = 0  

But if I Not only do I want to change a situation but in a complete line, I go into problems:

toChange = ['0', '0', ':'] #input by raw_input An array element with a [tochange] = 0

for this reason ValueError: setting a sequence . I can see that the problem is ':' string, because a [0, 0 ,:] = 0 does what I want. The question is how to pass the string to the string?

Or is there a smart way to manipulate user-defined slides?

PS: As I am working on an old Stable Debian, I use Python 2.6.6 and Nampi 1.4.1

: is a syntax for a piece object:

 > ; & Gt; & Gt; Class indicator (object): ... def __getitem __ (self, idx): ... back idx ... & gt; & Gt; & Gt; Indexable () [0, 0,:] (0, 0, piece (none, none, none))  

So if you type ':' Change the piece (none, none, none) you get the desired result:

  & gt; & Gt; & Gt; Tochange = [0, 0, piece (none, none, none)]> gt; & Gt; & Gt; A [tochange] = 0> & gt; & Gt; & Gt; An array ([0, 0, 0, 0], [4, 5, 6, 7], [8, 9, 10, 11]], [[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]]]]  

Comments