Hi guys,

So I have a list of objects, each which belong to a particular subclass. I am trying to calculate a running standard deviation as follows:

``````Label = []
Resistance = []
m = 0
i = 0
j = 0

if len(row) == 0 or row[0] == '':
i+=1
continue
else:
Resistance.append(tuple((float(x) if x.strip() else '0.0') for x in row[4:]))
i+=1

b1 = Resistance[2]
b2 = Resistance[3]
b3 = Resistance[4]
b4 = Resistance[5]
b5 = Resistance[6]
b6 = Resistance[7]

BR1 = []

BR1.append(b1)
BR1.append(b2)
BR1.append(b3)
BR1.append(b4)
BR1.append(b5)
BR1.append(b6)

numsB = array(BR1)

print numsB.std(axis=0)
``````

However this returns the error:

``````print numsB.std(axis=0)
TypeError: cannot perform reduce with flexible type
``````

I have been trying various methods to get it to work and I can't seem to figure out what's wrong.

Additionally, you may have noticed I inserted a '0.0' above wherever the excel spreadsheet contains a blank column, however I cannot keep it this way because I am calculating a standard deviation. Could I make it so that when Python calculates the StDev, wherever it encounters a '' it treats it as nothing, rather than zero? Thank you so much.

I think this is the culprit: Resistance.append(tuple((float(x) if x.strip() else '0.0'). On the one hand it's number, on the other, a string.

## All 2 Replies

I think this is the culprit: Resistance.append(tuple((float(x) if x.strip() else '0.0'). On the one hand it's number, on the other, a string.

And you can do this more compactly

``````BR1 = []
for ctr in range(2, 8):
BR1.append(Resistance[ctr]

## replaces
BR1 = []
b1 = Resistance[2]
b2 = Resistance[3]
b3 = Resistance[4]
b4 = Resistance[5]
b5 = Resistance[6]
b6 = Resistance[7]
BR1.append(b1)
BR1.append(b2)
BR1.append(b3)
BR1.append(b4)
BR1.append(b5)
BR1.append(b6)
``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.