Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc
Bàn luậnSciPy is a free and open-source Python library used for scientific computing and technical computing. SciPy contains modules for optimization, linear algebra, integration, interpolation, special functions, FFT, signal and image processing, ODE solvers and other tasks common in science and engineering.
Trong bài viết này, chúng ta sẽ xem làm thế nào chúng ta có thể tạo ra một biểu đồ chức năng khối xác suất Poisson trong Python. Trong lý thuyết và thống kê xác suất, phân phối Poisson là một phân phối xác suất riêng biệt thể hiện xác suất của một số lượng sự kiện nhất định xảy ra trong một khoảng thời gian hoặc không gian cố định nếu các sự kiện này xảy ra với tốc độ trung bình không đổi đã biết và độc lập về thời gian sự kiện cuôi cung. Phân phối Poisson cũng có thể được sử dụng cho số lượng sự kiện trong các khoảng thời gian được chỉ định khác như khoảng cách, diện tích hoặc khối lượng. & NBSP;
Syntax : poisson.pmf(k, mu, loc)
Argument : It takes numpy array, shape parameter and location as argument
Return : It returns numpy array
Để vẽ sơ đồ phân phối Poisson, chúng tôi sẽ sử dụng mô -đun SCIPY. Scipy là một thư viện Python miễn phí và nguồn mở được sử dụng để điện toán khoa học và điện toán kỹ thuật. SCIPY chứa các mô -đun để tối ưu hóa, đại số tuyến tính, tích hợp, nội suy, chức năng đặc biệt, FFT, xử lý tín hiệu và hình ảnh, bộ giải ODE và các nhiệm vụ khác phổ biến trong khoa học và kỹ thuật.
Python3
Để có được biểu đồ chức năng khối xác suất Poisson trong Python, chúng tôi sử dụng phương pháp Poisson.pmf của Scipy. mảng numpy & nbsp; & nbsp;
Ví dụ 1:
from scipy.stats import poisson
import numpy as np
import import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 0
import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 1import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 2 import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 3import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 4import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 5import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 6import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 5import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 8import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 9
from0
import numpy as np
import scipy.misc
import math
import matplotlib.pyplot as plt
t = np.arange(0, 20, 0.1)
x = np.power(t, 5)
y = scipy.misc.factorial(t)
plt.plot( t, x / y, 'bs')
plt.show()
0import numpy as np
import matplotlib.pyplot as plt
from scipy.special import factorial
t = np.arange(0, 20, 0.1)
d = np.exp(-5)*np.power(5, t)/factorial(t)
plt.plot(t, d, 'bs')
plt.show()
2 import numpy as np
import scipy.misc
import math
import matplotlib.pyplot as plt
t = np.arange(0, 20, 0.1)
x = np.power(t, 5)
y = scipy.misc.factorial(t)
plt.plot( t, x / y, 'bs')
plt.show()
2import numpy as np
import matplotlib.pyplot as plt
from scipy.special import factorial
t = np.arange(0, 20, 0.1)
d = np.exp(-5)*np.power(5, t)/factorial(t)
plt.plot(t, d, 'bs')
plt.show()
2import numpy as np
import scipy.misc
import math
import matplotlib.pyplot as plt
t = np.arange(0, 20, 0.1)
x = np.power(t, 5)
y = scipy.misc.factorial(t)
plt.plot( t, x / y, 'bs')
plt.show()
4import numpy as np
import scipy.misc
import math
import matplotlib.pyplot as plt
t = np.arange(0, 20, 0.1)
x = np.power(t, 5)
y = scipy.misc.factorial(t)
plt.plot( t, x / y, 'bs')
plt.show()
5__12
import numpy as np import scipy.misc import math import matplotlib.pyplot as plt t = np.arange(0, 20, 0.1) x = np.power(t, 5) y = scipy.misc.factorial(t) plt.plot( t, x / y, 'bs') plt.show() 9 Using step size of data as 1
Python3
Để có được biểu đồ chức năng khối xác suất Poisson trong Python, chúng tôi sử dụng phương pháp Poisson.pmf của Scipy. mảng numpy & nbsp; & nbsp;
Ví dụ 1:
from scipy.stats import poisson
import numpy as np
import import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 0
import numpy as np import scipy.misc import math import matplotlib.pyplot as plt t = np.arange(0, 20, 0.1) x = np.power(t, 5) y = scipy.misc.factorial(t) plt.plot( t, x / y, 'bs') plt.show() 9
from0
Output:
import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 1import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 2 import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 3import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 4import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 5import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 6import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 5import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 8import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 9 Plotting scatterplot for better viewing of data points
Python3
Để có được biểu đồ chức năng khối xác suất Poisson trong Python, chúng tôi sử dụng phương pháp Poisson.pmf của Scipy. mảng numpy & nbsp; & nbsp;
Ví dụ 1:
from scipy.stats import poisson
import numpy as np
import import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show() 0
numpy as np5
from0
Output:
3
Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.
Tôi muốn vẽ hàm Poisson trong Python bằng cách sử dụng matplotlib. Hàm là (exp (-5)*5^x)/factorial (x)
import numpy as np import math import matplotlib.pyplot as plt t = np.arange(0, 20, 0.1) d = [] for i in t: p = pow(5,i) q = p/math.factorial(i) d.append(q) plt.plot( t, np.exp(-5)*d, 'bs') plt.show()Nhưng tôi gặp lỗi này. "Chỉ có kích thước^1 mảng có thể được chuyển đổi thành vô hướng Python". Làm thế nào tôi có thể vẽ đồ thị này? Cảm ơn trước
hỏi ngày 9 tháng 7 năm 2018 lúc 9:57Jul 9, 2018 at 9:57
Sanjay Msanjay mSanjay M
Huy hiệu vàng 311 Huy hiệu bạc4 Huy hiệu đồng1 gold badge1 silver badge4 bronze badges
1
Tôi nghĩ rằng chức năng của bạn không đúng: đó là numpy as np7
import numpy as np import matplotlib.pyplot as plt from scipy.special import factorial t = np.arange(0, 20, 0.1) d = np.exp(-5)*np.power(5, t)/factorial(t) plt.plot(t, d, 'bs') plt.show()
Đã trả lời ngày 9 tháng 7 năm 2018 lúc 10:33Jul 9, 2018 at 10:33
Bobrobbobbobrobbobbobrobbob
1.22911 huy hiệu bạc21 Huy hiệu đồng11 silver badges21 bronze badges
1
Vấn đề ngay lập tức có lẽ là bạn đang sử dụng 'T' thay vì 'Tôi' trong vòng lặp của bạn. Tuy nhiên, bạn có thể muốn tránh trộn các danh sách python với các mảng numpy. Bạn có thể làm điều đó như,
import numpy as np import scipy.misc import math import matplotlib.pyplot as plt t = np.arange(0, 20, 0.1) x = np.power(t, 5) y = scipy.misc.factorial(t) plt.plot( t, x / y, 'bs') plt.show()Đã trả lời ngày 9 tháng 7 năm 2018 lúc 10:17Jul 9, 2018 at 10:17
Jownerjdownerjdowner
6981 Huy hiệu vàng7 Huy hiệu bạc 20 Huy hiệu đồng1 gold badge7 silver badges20 bronze badges