Something strange happens when I try to sum a numpy array (as a first summand) with an object of type electrical_signal or optical_signal, like this:
x = np.array([1,2,3])
y = electrical_signal([1,2,3])
x+y
Raise an exception
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: operands could not be broadcast together with shapes (3,) (3,2)
It seems that numpy's implementation of the __add__ operand somehow manages to interpret the object and translate it into an array of shape (3,2).
This problem don't appear when the first summand is an object other than an np.ndarray. For example:
from opticomlib import *
y = electrical_signal([1,2,3])
for x in [[1,2,3], (1,2,3), '1,2,3']:
print((x+y).__repr__())
It return:
electrical_signal([2 4 6])
electrical_signal([2 4 6])
electrical_signal([2 4 6])
When electrical_signal or optical_signal objects are first summand, the addition works well in all cases (because __add__ of these objects is executed).
from opticomlib import *
import numpy as np
y = electrical_signal([1,2,3])
for x in [np.array([1,2,3]), [1,2,3], (1,2,3), '1,2,3']:
print((y+x).__repr__())
electrical_signal([2 4 6])
electrical_signal([2 4 6])
electrical_signal([2 4 6])
electrical_signal([2 4 6])
Something strange happens when I try to sum a numpy array (as a first summand) with an object of type
electrical_signaloroptical_signal, like this:Raise an exception
It seems that numpy's implementation of the
__add__operand somehow manages to interpret the object and translate it into an array of shape (3,2).This problem don't appear when the first summand is an object other than an
np.ndarray. For example:It return:
When
electrical_signaloroptical_signalobjects are first summand, the addition works well in all cases (because__add__of these objects is executed).