I am using a 2D list, and I want to calculate the mean value of the line by the following code is mine :
import np mylist = np.zeros ((2,120)) # this gives you 2 rows 2 rows 2 rows, and gives 120 columns average_list = np xrange (120 ) .zeros (120) for the colonel: average_list [cola] = n.p.men (mylist [:] [cola])
However, the above part produces this: / P>
Indexing Error: The pointer is out of range for axis with 2/2
As I found during debugging, the problem occurs on
in np .mean (mylist [:] [col])
Do I know what I'm wrong about?
Thank you.
One way to fix your code (with minimal changes)
However, to avoid a better way for-loop
and axis = 0
:
average_array = myarray .mean (axis = 0) # 1
axis = 0
indicates mean
mean on the first axis, i.e. taking lines.
A small example of myarray [:] [col]
and myarray [,, col]
:
Can help see the difference between [7]: [7]: myarray = np.arange (6). Renewal (2,3) [8]: myarray out [8]: Array ([, 0, 1, 2], [3, 4, [9]: [9]: in [9]: [1] 2 [9]: [1] 2] in array ([0, 1, 2]) [10]: Marra [:, 0] outside [10]: array ([0, 3])
As you can see myarray selects the 0th line of copying one [:] [0]
) maryata . Then
myarray [:] [col]
raises an index error when col
is greater than 1, because there are only 2 rows
Comments
Post a Comment