需要在Python的Pareto分发代码中进行说明

问题描述 投票:0回答:1

您能否在代码中解释'output.T'?我在Google上进行了搜索,但找不到任何答案来更好地帮助代码。代码是绘制帕累托分布。

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()

在此代码中,output.T代表什么?具体来说,这里的T是什么?

python numpy scipy distribution
1个回答
1
投票

对于您的情况,看起来您将有一个列表列表转换为数组。 .T进行换位,类似于对数学中的矩阵进行运算。您可以通过以下方式查看差异:output.T.shapeoutput.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) 

请注意,这实际上与帕累托分布本身] >>无关,也许是因为帕累托支持矢量化,但对.T对象的操作中却支持np.array操作,因此那就是您想要在文档中寻找的东西。

© www.soinside.com 2019 - 2024. All rights reserved.