简体   繁体   中英

Need clarification in Pareto Distribution Code in Python

Can you please explain 'output.T' in code? 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? Specifically, what is T here?

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. You can see the difference via: output.T.shape vs. output.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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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