combining two different NumPy arrays
Solved
Independent Developers
-
hey everyone
first here is the code:In [1]: np.array([True, 1, 2]) + np.array([3, 4, False]) Out[1]: array([4, 5, 2])
I'm taking the Data Science course on scaler. One of the examples lacked an explanation of the numpy addition rules. I've attached a photo of the example as well as the query. What I didn't get was how two arrays with different values could be added together to produce such a result.
-
@Sachin-Bhatt My explanation: True evaluates to 1 in a numerical context. False evaluates to 0. So:
True +3 = 4 1 + 4 = 5 2 + False = 2
-