“Verhindern Sie die Teilung durch Zero Numpy” Code-Antworten

Verhindern Sie die Teilung durch Zero Numpy

>>> a = np.array([-1, 0, 1, 2, 3], dtype=float)
>>> b = np.array([ 0, 0, 0, 2, 2], dtype=float)

# If you don't pass `out` the indices where (b == 0) will be uninitialized!
>>> c = np.divide(a, b, out=np.zeros(a.shape, dtype=float), where=b!=0)
>>> print(c)
[ 0.   0.   0.   1.   1.5]
Real Raccoon

Verhindern Sie die Teilung durch Zero Numpy

>>> a = np.array([-1, 0, 1, 2, 3], dtype=float)
>>> b = np.array([ 0, 0, 0, 2, 2], dtype=float)

# If you don't pass `out` the indices where (b == 0) will be uninitialized!
>>> c = np.divide(a, b, out=np.zeros_like(a), where=b!=0)
>>> print(c)
[ 0.   0.   0.   1.   1.5]
Real Raccoon

Ähnliche Antworten wie “Verhindern Sie die Teilung durch Zero Numpy”

Fragen ähnlich wie “Verhindern Sie die Teilung durch Zero Numpy”

Weitere verwandte Antworten zu “Verhindern Sie die Teilung durch Zero Numpy” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen