Sử dụng python numpy Random.uniform

Vì chiều dài cuốn sách này có giới hạn nên chúng tôi không thể giới thiệu hết tất cả các chức năng và lớp của MXNet (và tốt nhất nên như vậy). API tài liệu, hướng dẫn và ví dụ sẽ cung cấp nhiều thông tin vượt qua nội dung cuốn sách. Trong chương trình này, chúng tôi sẽ cung cấp một số hướng dẫn duy nhất để bạn có thể khám phá MXNet API

2. 7. 1. Tra cứu tất cả các hàm và lớp trong một Mô-đun¶

Để biết những hàm/lớp nào có thể được gọi trong một mô-đun, chúng ta sử dụng hàm

['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_mx_nd_np', 'absolute_import', 'choice', 'multinomial', 'normal', 'rand', 'randint', 'shuffle', 'uniform']
0. Ví dụ, ta có thể lấy tất cả các thuộc tính của mô-đun
['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_mx_nd_np', 'absolute_import', 'choice', 'multinomial', 'normal', 'rand', 'randint', 'shuffle', 'uniform']
1 bằng cách

from mxnet import np
print(dir(np.random))

['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_mx_nd_np', 'absolute_import', 'choice', 'multinomial', 'normal', 'rand', 'randint', 'shuffle', 'uniform']

Thông thường, ta có thể bỏ qua các hàm bắt đầu và kết thúc bằng

['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_mx_nd_np', 'absolute_import', 'choice', 'multinomial', 'normal', 'rand', 'randint', 'shuffle', 'uniform']
2 (các đối tượng đặc biệt trong Python) hoặc các hàm bắt đầu bằng
['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_mx_nd_np', 'absolute_import', 'choice', 'multinomial', 'normal', 'rand', 'randint', 'shuffle', 'uniform']
3 (thường là các hàm địa phương). Dựa trên tên của các chức năng và thuộc tính còn lại, ta có thể dự đoán rằng mô-đun này cung cấp các phương thức sinh ngẫu nhiên ngẫu nhiên, bao gồm lấy mẫu từ phân phối đều liên tục (
['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_mx_nd_np', 'absolute_import', 'choice', 'multinomial', 'normal', 'rand', 'randint', 'shuffle', 'uniform']
0), phân phối chuẩn (

2. 7. 2. Tra cứu cách sử dụng một hàm hoặc một lớp công cụ có thể¶

To tra cứu chi tiết cách sử dụng một hàm hoặc lớp định nghĩa mới nhất, ta sử dụng hàm

['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_mx_nd_np', 'absolute_import', 'choice', 'multinomial', 'normal', 'rand', 'randint', 'shuffle', 'uniform']
3. Ví dụ, để nghiên cứu cách sử dụng hàm
['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_mx_nd_np', 'absolute_import', 'choice', 'multinomial', 'normal', 'rand', 'randint', 'shuffle', 'uniform']
4 với
['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_mx_nd_np', 'absolute_import', 'choice', 'multinomial', 'normal', 'rand', 'randint', 'shuffle', 'uniform']
5

________số 8

Help on function ones_like in module mxnet.numpy:

ones_like(a)
    Return an array of ones with the same shape and type as a given array.

    Parameters
    ----------
    a : ndarray
        The shape and data-type of a define these same attributes of
        the returned array.

    Returns
    -------
    out : ndarray
        Array of ones with the same shape and type as a.

    Examples
    --------
    >>> x = np.arange(6)
    >>> x = x.reshape((2, 3))
    >>> x
    array([[0., 1., 2.],
           [3., 4., 5.]])
    >>> np.ones_like(x)
    array([[1., 1., 1.],
           [1., 1., 1.]])

    >>> y = np.arange(3, dtype=float)
    >>> y
    array([0., 1., 2.], dtype=float64)
    >>>
    >>> np.ones_like(y)
    array([1., 1., 1.], dtype=float64)

Từ tài liệu, ta có thể thấy hàm

['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_mx_nd_np', 'absolute_import', 'choice', 'multinomial', 'normal', 'rand', 'randint', 'shuffle', 'uniform']
4 tạo một mảng mới có cùng kích thước với
['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_mx_nd_np', 'absolute_import', 'choice', 'multinomial', 'normal', 'rand', 'randint', 'shuffle', 'uniform']
5 nhưng tất cả các phần tử của nó đều chứa giá trị
['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_mx_nd_np', 'absolute_import', 'choice', 'multinomial', 'normal', 'rand', 'randint', 'shuffle', 'uniform']
8. Nếu có thể, bạn nên chạy thử để xác nhận rằng mình hiểu đúng

['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_mx_nd_np', 'absolute_import', 'choice', 'multinomial', 'normal', 'rand', 'randint', 'shuffle', 'uniform']
3

['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_mx_nd_np', 'absolute_import', 'choice', 'multinomial', 'normal', 'rand', 'randint', 'shuffle', 'uniform']
4

Trong sổ tay Jupyter, ta có thể sử dụng

['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_mx_nd_np', 'absolute_import', 'choice', 'multinomial', 'normal', 'rand', 'randint', 'shuffle', 'uniform']
9 để mở tài liệu trong một cửa sổ khác. Ví dụ,
help(np.ones_like)
0 sẽ đưa vào nội dung y tế
help(np.ones_like)
1 trong một cửa sổ trình duyệt mới. Ngoài ra, nếu chúng ta sử dụng dấu
['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_mx_nd_np', 'absolute_import', 'choice', 'multinomial', 'normal', 'rand', 'randint', 'shuffle', 'uniform']
9 hai lần như
help(np.ones_like)
3 thì đoạn mã định nghĩa hàm cũng sẽ có trong ra

2. 7. 3. API tài liệu¶

Chi tiết cụ thể về các API của MXNet có thể được tìm thấy tại trang http. // mxnet. apache. tổ chức/. Chi tiết từng phần được tìm thấy tại các mục tương ứng (cho cả các ngôn ngữ lập trình khác bên ngoài Python)