0
Can anybody help me?
Can anybody explain me this code(cannot understand matmul function), please: class l(list): def __matmul__(self,other): new=l() for k in range(len(other)): new.append(self[k]+other[k]) return new i1=l((1,2,3,4,5)) i2=l((9,8,7,6,5)) [email protected] print(sum(i3))
3 Answers
+ 3
I think you are struggling of __matmul__ and the @-operator. Both are related to matrix multiplication.
Find more information at:
https://stackoverflow.com/questions/27385633/what-is-the-symbol-for-in-python
+ 2
Normally the @ operator is used by numpy for matrix multiplication.
In your sample code, the meaning of this operator is overridden by the magic method __matmul__
Your class l is subclass of list, with the additional capability that two l objects can be combined with this operator. As it is implemented, it adds the values element-wise to create a new l object, so the result of [email protected] will be [10, 10, 10, 10, 10]
+ 1
Thank you Tibor Santa
Hot today
Please help, any idea?
2 Votes
Loop question, I've tried everything that I knew I just don't know. Please help me solve it out
1 Votes
What is wrong? Error on test.
1 Votes
Help me solve this (using loop)
1 Votes
Help me wiht python
1 Votes
how can i flip any word with c++
0 Votes