了解在单个语句中使用多个 python 装饰器
Understanding the use of multiple python decorators in a single statement
我最近发现了一个与下面给出的非常相似的代码片段:
def abc(a,b,c):
a1 = a[:, :1]
b1 = b[:1, :]
c1 = c[:1, :]
a2 = a1.conj().transpose()
b2 = c1.conj().transpose()
d = np.linalg.inv(np.sqrt(b1))
e = d @ a2 @ b @ b2 @ d
return e
a,b,c are numpy arrays.
我正在尝试理解 python 装饰器并从 this question 那里学到了一些东西。
但是我无法弄清楚变量 e
是如何定义的。到底发生了什么?
我是 Python 的初学者。据我所知,装饰器环绕一个函数并将函数作为参数传递。但是在这里,这些都是 numpy 数组。
任何关于定义变量 e
时究竟发生了什么的解释,或者在一行中包含多个装饰器的特定索引的含义,都将非常有帮助。
行 e = d @ a2 @ b @ b2 @ d
与 Python 装饰器无关。这里的@
字符是Python@
运算符:https://docs.python.org/3/library/operator.html#operator.matmul
LInk 到 PEP-465:https://www.python.org/dev/peps/pep-0465/
来自 numpy 文档 link:
The matmul function implements the semantics of the @ operator
introduced in Python 3.5 following PEP465.
我最近发现了一个与下面给出的非常相似的代码片段:
def abc(a,b,c):
a1 = a[:, :1]
b1 = b[:1, :]
c1 = c[:1, :]
a2 = a1.conj().transpose()
b2 = c1.conj().transpose()
d = np.linalg.inv(np.sqrt(b1))
e = d @ a2 @ b @ b2 @ d
return e
a,b,c are numpy arrays.
我正在尝试理解 python 装饰器并从 this question 那里学到了一些东西。
但是我无法弄清楚变量 e
是如何定义的。到底发生了什么?
我是 Python 的初学者。据我所知,装饰器环绕一个函数并将函数作为参数传递。但是在这里,这些都是 numpy 数组。
任何关于定义变量 e
时究竟发生了什么的解释,或者在一行中包含多个装饰器的特定索引的含义,都将非常有帮助。
行 e = d @ a2 @ b @ b2 @ d
与 Python 装饰器无关。这里的@
字符是Python@
运算符:https://docs.python.org/3/library/operator.html#operator.matmul
LInk 到 PEP-465:https://www.python.org/dev/peps/pep-0465/
来自 numpy 文档 link:
The matmul function implements the semantics of the @ operator introduced in Python 3.5 following PEP465.