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?

kmario23
  • 57,311
  • 13
  • 161
  • 150
Tuan Do
  • 357
  • 1
  • 2
  • 11

1 Answers1

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__.

user2357112
  • 260,549
  • 28
  • 431
  • 505