1

Say I have a python array and a numpy array

import numpy as np
python_array = [range(20), range(20), range(20)] 
numpy_array = np.array(python_array)

You can do:

numpy_array + python_array

However, this gives the same result:

python_array + numpy_array

while __add__ of a python array is just concatenation. In fact, if you do:

python_array.\__add__(numpy_array)

it gives:

 can only concatenate list (not "numpy.ndarray") to list

Can someone explain this to me?

1

1 Answer 1

1

There's also an __radd__ method for b to implement a + b if a doesn't understand the operation. You're seeing numpy.ndarray.__radd__.

Sign up to request clarification or add additional context in comments.

1 Comment

This is what I suspect but I didn't know there is a __radd__. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.