你能解释一下'输出吗。代码中的T?我在谷歌上搜索过,但找不到任何答案来帮助我更好地了解代码。代码是绘制帕累托分布图。
import numpy as np
from matplotlib import pyplot as plt
from scipy.stats import pareto
xm = 1 # scale
alphas = [1, 2, 3] # shape parameters
x = np.linspace(0, 5, 1000)
output = np.array([pareto.pdf(x, scale = xm, b = a) for a in alphas])
plt.plot(x, output.T)
plt.show()
在这段代码中,输出什么。T代表?具体来说,这里的T是什么?
对于您的情况,看起来您将把一个列表列表转换为一个数组。.T
采用转置,类似于数学中对矩阵的运算。您可以通过以下方式看到差异:output.T.shape
与。output.shape
这里有一个小例子:
>>> np.array([1, 2, 3], ndmin=2)
array([[1, 2, 3]])
>>> a = np.array([1, 2, 3], ndmin=2)
>>> a
array([[1, 2, 3]])
>>> a.shape
(1, 3)
>>> a.T
array([[1],
[2],
[3]])
>>> a.T.shape
(3, 1)
请注意,这实际上与Pareto分布本身没有任何关系,除了Pareto支持矢量化,但在对np.array
对象的操作中有.T
操作,所以这是您希望在文档中查找的。