Skip to content Skip to sidebar Skip to footer

"the Truth Value Of An Array With More Than One Element Is Ambiguous" In Python

this is how I got the two arrays (array 1 and array2) for my function: x = np.arange(-5, 5,0.01) prob=stats.norm.pdf(x,0,1) prob_array=numpy.array(prob).reshape(1000,1) #array1 x_t

Solution 1:

Welcome to SO! The problem seems to be this line: if z >= 0: If you use the '>'/'<' operator on an array it will return the following:

>>> import numpy as np
>>> a = np.array([1,2,3])
>>> a > 2
array([False, False,  True])

This array can't be converted to bool by default, you have to be more specific, for example by using any() to test if atleast one element falls under the given condition. Numpy arrays can do it like this: https://numpy.org/doc/stable/reference/generated/numpy.ndarray.any.html.

Post a Comment for ""the Truth Value Of An Array With More Than One Element Is Ambiguous" In Python"