简体   繁体   English

需要澄清 Python 中的帕累托分布代码

[英]Need clarification in Pareto Distribution Code in Python

Can you please explain 'output.T' in code?你能在代码中解释'output.T'吗? I have searched on google, but could not find any answers to help to know the code better.我在谷歌上搜索过,但找不到任何有助于更好地了解代码的答案。 The code is to plot Pareto distribution.代码是绘制帕累托分布。

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

In this code, what does output.T represent?在这段代码中,output.T 代表什么? Specifically, what is T here?具体来说,这里的T是什么?

For your case it looks like you'll have a list of lists converted into an array.对于您的情况,您似乎将一个列表列表转换为一个数组。 The .T takes a transpose, similar to the operation on matrices from mathematics. .T采用转置,类似于对数学矩阵的运算。 You can see the difference via: output.T.shape vs. output.shape :您可以通过看差output.T.shapeoutput.shape

here is a small example:这是一个小例子:

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

Note this doesn't really have anything to do with the Pareto distribution per se except maybe for the fact that Pareto supported vectorization but the .T operation in an operation on np.array object so that is what you'd want to be looking for in docs.请注意,这与帕累托分布本身没有任何关系,除非帕累托支持向量化,但在np.array对象上的操作中的.T操作,这就是您想要寻找的在文档中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM