Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

numpy divide with exception

>>> 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]
Comment

PREVIOUS NEXT
Code Example
Python :: how to add a value to a list in python 
Python :: sklearn classifiers 
Python :: bar plot bokeh 
Python :: python equals override 
Python :: python array slice 
Python :: install local package python 
Python :: split into list into even chunks 
Python :: .describe() python 
Python :: how to check dimension of array in python 
Python :: sum of 1 to even numbers in python 
Python :: python openpyxl cell width 
Python :: python tkinter label 
Python :: fibonacci 
Python :: pairplot with selected field 
Python :: split list on every nth element python 
Python :: python pandas in list 
Python :: how to call a random function in python 
Python :: python sum of list axes 
Python :: Python program to combine each line from first file with the corresponding line in second file 
Python :: how to replace a word in text file using python 
Python :: np.mean 
Python :: regex name extract 
Python :: rotating circular queue in python 
Python :: socket exception python 
Python :: depth first search python recursive 
Python :: django pagination 
Python :: looping on string with python 
Python :: save object pickle python 
Python :: python matplotlib 
Python :: print whole list python 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =