I am trying to compute the z-score of a ndarray (1x119) and put the results into a new one. But I got the 'The truth value of an array with more than one element is ambiguous' error.
Here's the code:
data = loadmat('data.mat') // return us a dict
ts_1 = data['exp1']
ts_2 = data['exp2']
ts_all = np.concatenate(ts_1,ts_2, axis=1)
ts_all = np.array(ts_all) // useless?
ts_all_z = np.zeros(ts_all.shape)
for i in range(ts_all.shape[1]):
ts_all_z[:,i] = stats.zscore(ts_all[:,i]) // error
I don't understand because I am not doing any boolean comparison...am I?
When looking at ts_all with np.info we get:
class: ndarray shape: (1, 119) strides: (952, 8) itemsize: 8 aligned: True contiguous: True fortran: True data pointer: 0x13b243030 byteorder: little byteswap: False type: object None
Also, ts_1 and 2 are ndarray of shape (1,22) and (1,24) respectively, of strides (8,8) both.
I think the concatenation is not done correctly? Or the iteration through ts_all shouldn't be done with .shape ...?
Thanks in advance.
So I found the problem but couldn't simply solve it, I had to just find another way of doing.
The problem seems to be that after concatenation, I have arrays of different size inside the ndarray.
For instance [[6, 7, 7], [12, 13, 13, 15]].
And stats.zscore doesn't like that: it finds it ambiguous because of the size difference: [[6, 7, 7], [12, 13, 13]] is therefore not an issue.
So what I did is simply compute the z scores first, and then concatenate.
In my case it is fine to do so, but it might not always be the case, for instance, if the concatenation needs to be done before to group the data together so the mean and std can be computed with all the data, then my solution doesn't work. Since each of the concatenated elements are from different experiences, I didn't want to mix the data before z-scoring anyway, I was just trying to make it easier to handle one single ndarray...I was wrong.