I'm trying to plot a graph of mean time period against load, the first column in my array is load and I want to exlude it from my mean calculation.
[[0.2 0.96 0.94 0.91 0.69 nan nan nan nan nan nan]
[0.3 1.15 1.09 1.19 1.19 1.31 0.97 0.97 nan nan nan]
[0.4 1.29 1.28 1.31 1.21 nan nan nan nan nan nan]
[0.5 1.54 1.43 1.45 1.37 1.35 1.29 nan nan nan nan]
[0.75 1.68 1.53 1.68 1.75 1.8 1.78 nan nan nan nan]
[1. 1.93 2.04 1.91 1.94 nan nan nan nan nan nan]]
#define the function
def clean_array(data):
"""Return a shortened array with any nans removed"""
return data[np.logical_not(np.isnan(data))]
clean_array(data[0]).mean(), clean_array(data[0]).std(ddof=1)
(0.74, 0.32070235421649157)
CodePudding user response:
simply slice the array and save it a new and then apply mean on it.
np.array(data)[:,1:]
CodePudding user response:
If all you're trying to do is remove the first column from every data list within your list, you can remove the first element in each list like so:
# assuming a structure of [[],[]]
data = [x.remove(0) for x in data]
This is list comprehension, essentially creating a new list of lists where for each element in your data object, you remove the first element and leave the rest of the list unchanged!