Why am I getting none? I am trying to have one list of standard deviations

Question:

My goal is to have one list of standard deviations from the data. I have 13 columns (features) in trainx and three labels(1,2,3) in trainy array corresponding to each row of trainx. My purpose is to find a feature which has minimum standard deviation.

I thought that first I’ll calculate standard deviation for each feature for label 1, append it in a list and then will find the minimum std deviation. I tried to write below code blocks but have been unsuccessful so far:

a=[]
for i in range(0,13):
    b=[np.std(trainx[trainy==1,i])]
    print(a.append(b))

It is returning this output:

None
None
None
None
None
None
None
None
None
None
None
None
None

If I try below code:

a=[]
for i in range(0,13):
    b=[np.std(trainx[trainy==1,i])]
    a=a.append(b)
print(a)

it returns:

AttributeError                            Traceback (most recent call last)
<ipython-input-78-6b02e93115a0> in <module>
      3 for i in range(0,13):
      4     b=[np.std(trainx[trainy==1,i])]
----> 5     a=a.append(b)
      6 print(a)

AttributeError: 'NoneType' object has no attribute 'append'

Please help me. Other ways are welcome too.

Asked By: Deepak Dhiman

||

Answers:

list.append doesn’t return the list. It only appends the object to the list. To get the list after you append, just access the list.

a=[]
for i in range(0,13):
    b=[np.std(trainx[trainy==1,i])]
    a.append(b)
    print(a)
Answered By: noteness
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.