You could feed the data into a numpy masked array, then compute the means with np.ma. Mean : import numpy as np import itertools data=1,2,3,1,2,3,1,2,3,4 rows=len(data) cols=max(len(row) for row in data) arr=np.ma. Zeros((rows,cols)) arr.
Mask=True for i,row in enumerate(data): arri,:len(row)=row print(arr. Mean(axis=0)) yields 1.0 2.0 3.0 4.0 Elements of the array get unmasked (i. E arr.
Maski,j=False ) when a value is assigned. Note the resultant mask below: In 162: arr Out162: masked_array(data = 1.0 2.0 3.0 -- 1.0 2.0 3.0 -- 1.0 2.0 3.0 4.0, mask = False False False True False False False True False False False False, fill_value = 1e+20) If your data is rather short yosukesabai's method or a pure Python solution is likely to be faster than what I show above. Only invest in making a masked array if the data is very large and you have enough numpy operations to perform on the array to make the initial cost of setting up the array worth it.
You could feed the data into a numpy masked array, then compute the means with np.ma. Mean: import numpy as np import itertools data=1,2,3,1,2,3,1,2,3,4 rows=len(data) cols=max(len(row) for row in data) arr=np.ma. Zeros((rows,cols)) arr.
Mask=True for i,row in enumerate(data): arri,:len(row)=row print(arr. Mean(axis=0)) yields 1.0 2.0 3.0 4.0 Elements of the array get unmasked (i.e. Arr.
Maski,j=False) when a value is assigned. Note the resultant mask below: In 162: arr Out162: masked_array(data = 1.0 2.0 3.0 -- 1.0 2.0 3.0 -- 1.0 2.0 3.0 4.0, mask = False False False True False False False True False False False False, fill_value = 1e+20) If your data is rather short, yosukesabai's method or a pure Python solution is likely to be faster than what I show above. Only invest in making a masked array if the data is very large and you have enough numpy operations to perform on the array to make the initial cost of setting up the array worth it.
This looks neat! – yosukesabai Nov 12 at 19:19 @yosukesabai: Thanks. I like your method too.
Please undelete it :) – unutbu Nov 12 at 19:21 undeleted. Interesting to know about setup cost, which I often forget. – yosukesabai Nov 12 at 19:27.
The only workaround I can think of is to use itertools and temporary list, not very beautiful. Import numpy as np from itertools import izip_longest table = 1,2,3,1,2,3,1,2,3,4 for row in izip_longest(*table): print np. Average(x for x in row if x is not None) This yields 1.0 2.0 3.0 4.0.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.