Operators permitted in ndarray vector operations

Question:

Question

I want to know the list of the Operators permitted in ndarray vector operations.

Question Details

Numpy ndarray can do vector operations such as:

arr  = np.array ( [ [ 1, 2, 3], [ 4, 5, 6] ] )
arr2 = np.array ( [ [-1,-2,-3], [-4,-5,-6] ] )
arr * arr2

However, for example, Operator "or" can’t use ndarray vector operations such as:

arr  = np.array ( [ [ True, False, True], [ False, True, False] ] )
arr2 = np.array ( [ [True,True,True], [False,False,False] ] )
arr or arr2

Result

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[196], line 1
----> 1 arr or arr2

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I expected: Or operation is done by each elements.

[ [ True, True, True], [ False, True, False] ] 

Then, I want to know the list of the Operators permitted in ndarray vector operations.

What I try

I searched official documents roughly, but I couldn’t find what operators are permitted in ndarray vector operations.
https://numpy.org/doc/stable/

Help

Anybody has (official) information about this ?

write above body "What I try"

Asked By: Horiemon_Hack

||

Answers:

Official Docs says permitted numpy vector operations are:

(+, -, *, /, //, %, divmod(), ** or pow(), <<, >>, &, ^, |, ~) and the comparisons (==, <, >, <=, >=, !=)

https://numpy.org/doc/stable/reference/arrays.ndarray.html#arithmetic-matrix-multiplication-and-comparison-operations

Answered By: Horiemon_Hack
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.