Can't use scipy stats function on nested list

71 views Asked by At

I've been trying to scipy.mstats.zscore a dataset that is intentionally organized into a nested list, and it gives:

TypeError: unsupported operand type(s) for /: 'list' and 'long'

which probably suggests that scipy.stats doesn't work for nested lists.

What can I do about it? Does a for loop affect the nature of the zscore when applied to the dataset in a "subset" way?

e.g.

dataset = [[1.5,3.3,2.6,5.8],[1.5,3.2,5.6,1.8],[2.5,3.1,3.6,5.2]]
zscore_dataset = zscore(dataset)

vs

zscore_dataset = []
for zscore_list in zscore_dataset,
    list = zscore(zscore_list)
    zscore_dataset.append(zscore_dataset)
1

There are 1 answers

0
Ami Tavory On BEST ANSWER

You need to apply it on a numpy.array reflecting the nested lists.

from scipy import stats
import numpy as np

dataset = np.array([[1.5,3.3,2.6,5.8],[1.5,3.2,5.6,1.8],[2.5,3.1,3.6,5.2]])
stats.mstats.zscore(dataset)

works fine.