numpy
. It is your task to allow C++
std::vector to be used for calculation following roughly the same API as
numpy's arrays.
+
operator (operator+
)
for vectors of the same type to
represent the following behavior.
The resulting new vector must contain the
sum of each element whenever the element's index exists in both
vectors.
If one vector has more elements than the other, the additional elements
should be taken without modification. For example:
// v1: 1, 2, 3
// v2: 7, 8
v3 = v1 + v2; // v3: 8, 10, 3 (1+7, 2+8, 3)

operator (operator
) in a
similar way to the +
operator.
*
operator (operator*
) for
vectors of the same type to represent the following behavior.
The resulting
vector must contain the product of each element whenever the element's
index exists in both vectors.
If one vector has more elements than the other, display an error
message and exit the program. For example:
// v1: 1, 2, 3
// v2: 7, 8, 9
v3 = v1 * v2; // v3: 7, 16, 27 (1*7, 2*8, 3*9)
*
operator (operator*
) for
multiplying a vector with a scalar of the same type as the vector.
It must be possible to write scalar * vector as well as
vector * scalar.
Return a new vector that has each element of the given vector
multiplied by the scalar. For example:
// v1: 1, 2, 3
// scalar: 3
v2 = v1 * 3; // v2: 3, 6, 9 (1*3, 2*3, 3*3)
v3 = 5 * v1; // v3: 5, 10, 15