Bipin
Bipin

Reputation: 483

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?

Upvotes: 0

Views: 142

Answers (1)

Lucas Roberts
Lucas Roberts

Reputation: 1343

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.

Upvotes: 4

Related Questions