Làm thế nào để bạn sử dụng chức năng bình thường trong python?

Trong bài viết này, chúng ta sẽ xem xét sự khác biệt cơ bản giữa Numpy. ngẫu nhiên. phương thức rand() và Numpy. ngẫu nhiên. chi tiết về phương thức normal()

  • Giới thiệu ngẫu nhiên. Đối với ngẫu nhiên chúng tôi đang lấy. rand()
    numpy. ngẫu nhiên. rand(d0, d1, …, dn).
    tạo một mảng có hình dạng cụ thể và
    điền vào đó các giá trị ngẫu nhiên.
    Thông số.
    d0, d1, ..., dn : [int, optional]
    Dimension of the returned array we require, 
    
    If no argument is given a single Python float 
    is returned.
    

    Trở về

    Array of defined shape, filled with random values.
    
  • Khoảng bình thường. Đối với ngẫu nhiên chúng tôi đang lấy. normal()
    numpy. ngẫu nhiên. bình thường (loc = 0. 0, tỷ lệ = 1. 0, kích thước = Không có). tạo một mảng có hình dạng được chỉ định và lấp đầy nó bằng các giá trị ngẫu nhiên, đây thực sự là một phần của Phân phối bình thường (Gaussian). Đây là Phân phối còn được gọi là Đường cong hình chuông vì hình dạng đặc trưng của nó.
    Thông số.
    loc   : [float or array_like]Mean of 
    the distribution. 
    scale : [float or array_like]Standard 
    Derivation of the distribution. 
    size  : [int or int tuples]. 
    Output shape given as (m, n, k) then
    m*n*k samples are drawn. If size is 
    None(by default), then a single value
    is returned. 
    

    Trở về

    Array of defined shape, filled with 
    random values following normal 
    distribution.
    
  • mã 1. Xây dựng ngẫu nhiên mảng 1D




    Array of defined shape, filled with random values.
    
    33

    Array of defined shape, filled with random values.
    
    34

    Array of defined shape, filled with random values.
    
    35

    Array of defined shape, filled with random values.
    
    0
    Array of defined shape, filled with random values.
    
    1

    Array of defined shape, filled with random values.
    
    35

    Array of defined shape, filled with random values.
    
    3

    Array of defined shape, filled with random values.
    
    4
    Array of defined shape, filled with random values.
    
    5
    Array of defined shape, filled with random values.
    
    6
    Array of defined shape, filled with random values.
    
    7
    Array of defined shape, filled with random values.
    
    8

    Array of defined shape, filled with random values.
    
    9
    loc   : [float or array_like]Mean of 
    the distribution. 
    scale : [float or array_like]Standard 
    Derivation of the distribution. 
    size  : [int or int tuples]. 
    Output shape given as (m, n, k) then
    m*n*k samples are drawn. If size is 
    None(by default), then a single value
    is returned. 
    
    0____21
    loc   : [float or array_like]Mean of 
    the distribution. 
    scale : [float or array_like]Standard 
    Derivation of the distribution. 
    size  : [int or int tuples]. 
    Output shape given as (m, n, k) then
    m*n*k samples are drawn. If size is 
    None(by default), then a single value
    is returned. 
    
    2

    đầu ra

    Array of defined shape, filled with random values.
    
    6

    mã 2. Xây dựng ngẫu nhiên mảng 1D theo Phân phối Gaussian




    Array of defined shape, filled with random values.
    
    33

    loc   : [float or array_like]Mean of 
    the distribution. 
    scale : [float or array_like]Standard 
    Derivation of the distribution. 
    size  : [int or int tuples]. 
    Output shape given as (m, n, k) then
    m*n*k samples are drawn. If size is 
    None(by default), then a single value
    is returned. 
    
    4

    Array of defined shape, filled with random values.
    
    35

    Array of defined shape, filled with random values.
    
    0
    Array of defined shape, filled with random values.
    
    1

    Array of defined shape, filled with random values.
    
    35

    Array of defined shape, filled with random values.
    
    3

    Array of defined shape, filled with random values.
    
    4
    Array of defined shape, filled with random values.
    
    5
    Array of defined shape, filled with 
    random values following normal 
    distribution.
    
    2
    Array of defined shape, filled with 
    random values following normal 
    distribution.
    
    3
    Array of defined shape, filled with 
    random values following normal 
    distribution.
    
    4
    Array of defined shape, filled with 
    random values following normal 
    distribution.
    
    5
    Array of defined shape, filled with 
    random values following normal 
    distribution.
    
    4
    Array of defined shape, filled with random values.
    
    7
    Array of defined shape, filled with random values.
    
    8

    Array of defined shape, filled with random values.
    
    9
    loc   : [float or array_like]Mean of 
    the distribution. 
    scale : [float or array_like]Standard 
    Derivation of the distribution. 
    size  : [int or int tuples]. 
    Output shape given as (m, n, k) then
    m*n*k samples are drawn. If size is 
    None(by default), then a single value
    is returned. 
    
    0____161

    Array of defined shape, filled with random values.
    
    62
    Array of defined shape, filled with random values.
    
    63____22

    Array of defined shape, filled with random values.
    
    65

    Array of defined shape, filled with random values.
    
    4
    Array of defined shape, filled with random values.
    
    5
    Array of defined shape, filled with 
    random values following normal 
    distribution.
    
    2
    Array of defined shape, filled with 
    random values following normal 
    distribution.
    
    3
    Array of defined shape, filled with 
    random values following normal 
    distribution.
    
    4
    Array of defined shape, filled with 
    random values following normal 
    distribution.
    
    5
    Array of defined shape, filled with random values.
    
    32
    Array of defined shape, filled with random values.
    
    33
    Array of defined shape, filled with 
    random values following normal 
    distribution.
    
    4
    Array of defined shape, filled with random values.
    
    35
    Array of defined shape, filled with 
    random values following normal 
    distribution.
    
    4
    Array of defined shape, filled with random values.
    
    33
    Array of defined shape, filled with random values.
    
    38

    Array of defined shape, filled with random values.
    
    9
    loc   : [float or array_like]Mean of 
    the distribution. 
    scale : [float or array_like]Standard 
    Derivation of the distribution. 
    size  : [int or int tuples]. 
    Output shape given as (m, n, k) then
    m*n*k samples are drawn. If size is 
    None(by default), then a single value
    is returned. 
    
    0____521

    Array of defined shape, filled with random values.
    
    62
    Array of defined shape, filled with random values.
    
    63____22

    đầu ra

    Array of defined shape, filled with random values.
    
    3


    mã3. Chương trình Python minh họa biểu diễn đồ họa của ngẫu nhiên so với bình thường trong NumPy




    Array of defined shape, filled with random values.
    
    33

    Array of defined shape, filled with random values.
    
    26

    loc   : [float or array_like]Mean of 
    the distribution. 
    scale : [float or array_like]Standard 
    Derivation of the distribution. 
    size  : [int or int tuples]. 
    Output shape given as (m, n, k) then
    m*n*k samples are drawn. If size is 
    None(by default), then a single value
    is returned. 
    
    4

    Array of defined shape, filled with random values.
    
    34

    Array of defined shape, filled with random values.
    
    35

    Array of defined shape, filled with random values.
    
    0
    Array of defined shape, filled with random values.
    
    1

    Array of defined shape, filled with random values.
    
    0
    Array of defined shape, filled with random values.
    
    333

    Array of defined shape, filled with random values.
    
    35

    Array of defined shape, filled with random values.
    
    335

    Array of defined shape, filled with random values.
    
    336
    Array of defined shape, filled with random values.
    
    5
    Array of defined shape, filled with random values.
    
    338

    Array of defined shape, filled with random values.
    
    339
    Array of defined shape, filled with random values.
    
    5
    Array of defined shape, filled with random values.
    
    341

    Array of defined shape, filled with random values.
    
    4
    Array of defined shape, filled with random values.
    
    5
    Array of defined shape, filled with 
    random values following normal 
    distribution.
    
    2
    Array of defined shape, filled with random values.
    
    338
    Array of defined shape, filled with 
    random values following normal 
    distribution.
    
    4
    Array of defined shape, filled with random values.
    
    341
    Array of defined shape, filled with 
    random values following normal 
    distribution.
    
    4
    Array of defined shape, filled with random values.
    
    349
    Array of defined shape, filled with random values.
    
    8

    Array of defined shape, filled with random values.
    
    9
    loc   : [float or array_like]Mean of 
    the distribution. 
    scale : [float or array_like]Standard 
    Derivation of the distribution. 
    size  : [int or int tuples]. 
    Output shape given as (m, n, k) then
    m*n*k samples are drawn. If size is 
    None(by default), then a single value
    is returned. 
    
    0____161

    _______162____163____1356

    Array of defined shape, filled with random values.
    
    357

    Array of defined shape, filled with random values.
    
    358

    Array of defined shape, filled with random values.
    
    359

    Array of defined shape, filled with random values.
    
    00

    Array of defined shape, filled with random values.
    
    01
    Array of defined shape, filled with random values.
    
    5
    Array of defined shape, filled with random values.
    
    03
    Array of defined shape, filled with random values.
    
    04
    Array of defined shape, filled with random values.
    
    05
    Array of defined shape, filled with random values.
    
    5
    Array of defined shape, filled with random values.
    
    07
    Array of defined shape, filled with random values.
    
    8

    Array of defined shape, filled with random values.
    
    09
    Array of defined shape, filled with random values.
    
    35
    Array of defined shape, filled with random values.
    
    11
    Array of defined shape, filled with random values.
    
    12
    Array of defined shape, filled with random values.
    
    13
    Array of defined shape, filled with random values.
    
    14
    Array of defined shape, filled with random values.
    
    33
    Array of defined shape, filled with random values.
    
    13
    Array of defined shape, filled with random values.
    
    17
    Array of defined shape, filled with random values.
    
    13

    Array of defined shape, filled with random values.
    
    19
    Array of defined shape, filled with random values.
    
    20
    Array of defined shape, filled with random values.
    
    21
    Array of defined shape, filled with random values.
    
    22
    Array of defined shape, filled with random values.
    
    21
    Array of defined shape, filled with random values.
    
    24
    Array of defined shape, filled with random values.
    
    13
    Array of defined shape, filled with random values.
    
    13
    Array of defined shape, filled with random values.
    
    33
    Array of defined shape, filled with random values.
    
    11
    loc   : [float or array_like]Mean of 
    the distribution. 
    scale : [float or array_like]Standard 
    Derivation of the distribution. 
    size  : [int or int tuples]. 
    Output shape given as (m, n, k) then
    m*n*k samples are drawn. If size is 
    None(by default), then a single value
    is returned. 
    
    0
    Array of defined shape, filled with random values.
    
    33
    Array of defined shape, filled with random values.
    
    13
    Array of defined shape, filled with random values.
    
    339
    Array of defined shape, filled with random values.
    
    13
    Array of defined shape, filled with random values.
    
    13
    Array of defined shape, filled with random values.
    
    33
    Array of defined shape, filled with random values.
    
    36

    Array of defined shape, filled with random values.
    
    19
    Array of defined shape, filled with random values.
    
    38
    Array of defined shape, filled with random values.
    
    5______433
    Array of defined shape, filled with random values.
    
    41
    Array of defined shape, filled with random values.
    
    5
    Array of defined shape, filled with random values.
    
    43
    Array of defined shape, filled with random values.
    
    8

    Array of defined shape, filled with random values.
    
    45

    Array of defined shape, filled with random values.
    
    357

    Array of defined shape, filled with random values.
    
    357

    Array of defined shape, filled with random values.
    
    48

    Array of defined shape, filled with random values.
    
    49
    Array of defined shape, filled with random values.
    
    5
    Array of defined shape, filled with random values.
    
    6
    Array of defined shape, filled with random values.
    
    7
    Array of defined shape, filled with random values.
    
    8

    Array of defined shape, filled with random values.
    
    9
    loc   : [float or array_like]Mean of 
    the distribution. 
    scale : [float or array_like]Standard 
    Derivation of the distribution. 
    size  : [int or int tuples]. 
    Output shape given as (m, n, k) then
    m*n*k samples are drawn. If size is 
    None(by default), then a single value
    is returned. 
    
    0____21
    Array of defined shape, filled with random values.
    
    57

    Array of defined shape, filled with random values.
    
    357

    Array of defined shape, filled with random values.
    
    59

    Array of defined shape, filled with random values.
    
    45

    đầu ra

    Array of defined shape, filled with random values.
    
    2

    Quan trọng.
    Trong mã 3, ô 1 hiển thị rõ ràng Phân phối Gaussian khi nó được tạo từ các giá trị được tạo thông qua ngẫu nhiên. phương thức normal() do đó tuân theo Phân phối Gaussian.
    ô 2 không tuân theo bất kỳ phân phối nào vì nó đang được tạo từ các giá trị ngẫu nhiên được tạo ngẫu nhiên. phương thức rand().

    Ghi chú.
    Mã 3 sẽ không chạy trên ID trực tuyến. Vui lòng chạy chúng trên hệ thống của bạn để khám phá hoạt động.
    .
    Bài viết này được đóng góp bởi Mohit Gupta_OMG 😀. Nếu bạn thích GeeksforGeeks và muốn đóng góp, bạn cũng có thể viết một bài báo bằng cách sử dụng đóng góp. chuyên viên máy tính. org hoặc gửi bài viết của bạn tới donate@geeksforgeeks. tổ chức. Xem bài viết của bạn xuất hiện trên trang chính của GeeksforGeeks và trợ giúp các Geeks khác.

    Vui lòng viết bình luận nếu bạn thấy bất cứ điều gì không chính xác hoặc bạn muốn chia sẻ thêm thông tin về chủ đề thảo luận ở trên

    Làm thế nào để bình thường ngẫu nhiên làm việc?

    Hoạt động của hàm normal() ngẫu nhiên NumPy . generates a random sample of the numbers of specified size, loc, and scale from the normal distribution and return as an array of dimensional specified in size.

    NP ngẫu nhiên bình thường () là gì?

    np. ngẫu nhiên. normal(1) Mã này sẽ tạo ra một số duy nhất được rút ra từ phân phối chuẩn với giá trị trung bình là 0 và độ lệch chuẩn là 1 .