Hướng dẫn 4d array python - Python mảng 4d

Một ndarray là một container đa chiều (thường có kích thước cố định) của các mặt hàng cùng loại và kích thước. Số lượng kích thước và vật phẩm trong một mảng được xác định bởi shape của nó, đây là một số nguyên không âm n chỉ định kích thước của từng chiều. Loại mục trong mảng được chỉ định bởi một đối tượng loại dữ liệu riêng biệt (DTYPE), một trong số đó được liên kết với mỗi ndarray.data-type object (dtype), one of which is associated with each ndarray.

Cũng như các đối tượng container khác trong Python, nội dung của ndarray có thể được truy cập và sửa đổi bằng cách lập chỉ mục hoặc cắt mảng (ví dụ, sử dụng các số nguyên n) và thông qua các phương thức và thuộc tính của ndarray.indexing or slicing the array (using, for example, N integers), and via the methods and attributes of the ndarray.

ndarrays khác nhau có thể chia sẻ cùng một dữ liệu, do đó các thay đổi được thực hiện trong một ndarray có thể được hiển thị trong một ndarray khác. Đó là, một ndarray có thể là một chế độ xem của người khác đối với một ndarray khác và dữ liệu mà nó đề cập đến được chăm sóc bởi cơ sở của Ndarray. Ndarrays cũng có thể là các chế độ xem vào bộ nhớ thuộc sở hữu của Python

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
1 hoặc các đối tượng thực hiện giao diện
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
2 hoặc mảng.array interfaces.

Thí dụ

Một mảng 2 chiều có kích thước 2 x 3, bao gồm các phần tử số nguyên 4 byte:

>>> x = np.array([[1, 2, 3], [4, 5, 6]], np.int32)
>>> type(x)

>>> x.shape
(2, 3)
>>> x.dtype
dtype('int32')

Mảng có thể được lập chỉ mục bằng cú pháp giống như container Python:

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6

Ví dụ, cắt lát có thể tạo ra chế độ xem của mảng:slicing can produce views of the array:

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)

Xây dựng mảng#

Các mảng mới có thể được xây dựng bằng cách sử dụng các thói quen chi tiết trong các thói quen tạo mảng, và cũng bằng cách sử dụng hàm tạo ndarray cấp thấp:Array creation routines, and also by using the low-level ndarray constructor:

ndarray(shape[, dtype, buffer, offset, ...])

Một đối tượng mảng đại diện cho một mảng đa chiều, đồng nhất của các mục có kích thước cố định.

Mảng lập chỉ mục#

Các mảng có thể được lập chỉ mục bằng cú pháp cắt python mở rộng,

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
5. Cú pháp tương tự cũng được sử dụng để truy cập các trường trong kiểu dữ liệu có cấu trúc.structured data type.

Bố cục bộ nhớ trong của ndarray#

Một thể hiện của lớp ndarray bao gồm một phân đoạn một chiều liền kề của bộ nhớ máy tính (thuộc sở hữu của mảng hoặc bởi một số đối tượng khác), kết hợp với sơ đồ lập chỉ mục ánh xạ N số nguyên vào vị trí của một mục trong khối. Các phạm vi trong đó các chỉ số có thể thay đổi được chỉ định bởi shape của mảng. Có bao nhiêu byte mỗi mục và cách các byte được giải thích được xác định bởi đối tượng loại dữ liệu được liên kết với mảng.data-type object associated with the array.

Một đoạn bộ nhớ vốn có 1 chiều và có nhiều sơ đồ khác nhau để sắp xếp các mục của một mảng N chiều trong một khối 1 chiều. Numpy là linh hoạt và các đối tượng ndarray có thể phù hợp với bất kỳ sơ đồ lập chỉ mục sải. Trong một sơ đồ sải, chỉ số n chiều \ ((n_0, n_1, ..., n_ {n-1}) \) tương ứng với phần bù (tính bằng byte):\((n_0, n_1, ..., n_{N-1})\) corresponds to the offset (in bytes):

\ [n _ {\ mathrm {offset}} = \ sum_ {k = 0}^{n-1} s_k n_k \]

Từ đầu khối bộ nhớ liên kết với mảng. Ở đây, \ (s_k \) là các số nguyên chỉ định

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
9 của mảng. Thứ tự Major Cột (ví dụ, được sử dụng trong ngôn ngữ Fortran và trong MATLAB) và thứ tự Major (được sử dụng trong C) chỉ là các loại sơ đồ sải tính cụ thể và tương ứng với bộ nhớ có thể được giải quyết bằng các bước tiến:\(s_k\) are integers which specify the
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
9 of the array. The column-major order (used, for example, in the Fortran language and in Matlab) and row-major order (used in C) schemes are just specific kinds of strided scheme, and correspond to memory that can be addressed by the strides:

\ [s_k^{\ mathrm {cột}} = \ mathrm {item prod_ {j = k+1}^{n-1} d_j. \]

trong đó \ (d_j \) = self.shape [j].\(d_j\) = self.shape[j].

Cả hai đơn đặt hàng C và Fortran đều liền kề, tức là, bố cục bộ nhớ đơn, trong đó mọi phần của khối bộ nhớ có thể được truy cập bằng một số kết hợp của các chỉ số.contiguous, i.e., single-segment, memory layouts, in which every part of the memory block can be accessed by some combination of the indices.

Ghi chú

Các mảng tiếp giáp và các mảng một đoạn là đồng nghĩa và được sử dụng thay thế cho nhau trong suốt tài liệu.

Mặc dù một mảng liền kề kiểu C và kiểu Fortran, có các cờ tương ứng, có thể được giải quyết với các bước trên, các bước thực tế có thể khác nhau. Điều này có thể xảy ra trong hai trường hợp:

  1. Nếu

    >>> y = x[:,1]
    >>> y
    array([2, 5], dtype=int32)
    >>> y[0] = 9 # this also changes the corresponding element in x
    >>> y
    array([9, 5], dtype=int32)
    >>> x
    array([[1, 9, 3],
           [4, 5, 6]], dtype=int32)
    
    0 thì cho bất kỳ chỉ số pháp lý
    >>> y = x[:,1]
    >>> y
    array([2, 5], dtype=int32)
    >>> y[0] = 9 # this also changes the corresponding element in x
    >>> y
    array([9, 5], dtype=int32)
    >>> x
    array([[1, 9, 3],
           [4, 5, 6]], dtype=int32)
    
    1. Điều này có nghĩa là trong công thức cho phần bù \ (n_k = 0 \) và do đó \ (s_k n_k = 0 \) và giá trị của \ (s_k \) = self.strides [k] là tùy ý.\(n_k = 0\) and thus \(s_k n_k = 0\) and the value of \(s_k\) = self.strides[k] is arbitrary.

  2. Nếu một mảng không có yếu tố (

    >>> y = x[:,1]
    >>> y
    array([2, 5], dtype=int32)
    >>> y[0] = 9 # this also changes the corresponding element in x
    >>> y
    array([9, 5], dtype=int32)
    >>> x
    array([[1, 9, 3],
           [4, 5, 6]], dtype=int32)
    
    2), không có chỉ số pháp lý và các bước tiến không bao giờ được sử dụng. Bất kỳ mảng nào không có yếu tố có thể được coi là kiểu C và kiểu Fortran.

Điểm 1. có nghĩa là

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
3 và
>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
4 luôn có cùng sự tiếp giáp và giá trị cờ
>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
5. Điều này cũng có nghĩa là ngay cả một mảng chiều cao cũng có thể là kiểu C và kiểu Fortran liên tục cùng một lúc.

Một mảng được coi là căn chỉnh nếu bộ nhớ bù đắp cho tất cả các phần tử và bản thân phần mềm cơ sở là bội số của self.itemsize. Hiểu về sự liên kết bộ nhớ dẫn đến hiệu suất tốt hơn trên hầu hết các phần cứng.

Cảnh báo

Nói chung, nó không cho rằng

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
6 đối với các mảng tiếp giáp kiểu C hoặc
>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
7 cho các mảng tiếp giáp kiểu Fortran là đúng.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
8 có thể được sử dụng để giúp tìm lỗi khi không chính xác dựa vào các bước tiến trong mã mở rộng C (xem bên dưới Cảnh báo).

Dữ liệu trong ndarrays mới theo thứ tự Major (C) mới, trừ khi có quy định khác, nhưng, ví dụ, việc cắt mảng cơ bản thường tạo ra các chế độ xem trong một sơ đồ khác.row-major (C) order, unless otherwise specified, but, for example, basic array slicing often produces views in a different scheme.

Ghi chú

Một số thuật toán trong công việc numpy trên các mảng sải tùy ý. Tuy nhiên, một số thuật toán yêu cầu các mảng một đoạn. Khi một mảng sải không đều được truyền vào các thuật toán như vậy, một bản sao được tự động thực hiện.

Thuộc tính mảng#

Các thuộc tính mảng phản ánh thông tin nội tại của chính mảng. Nói chung, truy cập một mảng thông qua các thuộc tính của nó cho phép bạn có được và đôi khi đặt các thuộc tính nội tại của mảng mà không tạo ra một mảng mới. Các thuộc tính tiếp xúc là các phần cốt lõi của một mảng và chỉ một số trong số chúng có thể được đặt lại một cách có ý nghĩa mà không tạo ra một mảng mới. Thông tin về mỗi thuộc tính được đưa ra dưới đây.

Bố cục bộ nhớ#

Các thuộc tính sau đây chứa thông tin về bố cục bộ nhớ của mảng:

>>> x = np.arange(27).reshape((3,3,3))
>>> x
array([[[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8]],
       [[ 9, 10, 11],
        [12, 13, 14],
        [15, 16, 17]],
       [[18, 19, 20],
        [21, 22, 23],
        [24, 25, 26]]])
>>> x.sum(axis=0)
array([[27, 30, 33],
       [36, 39, 42],
       [45, 48, 51]])
>>> # for sum, axis is the first keyword, so we may omit it,
>>> # specifying only its value
>>> x.sum(0), x.sum(1), x.sum(2)
(array([[27, 30, 33],
        [36, 39, 42],
        [45, 48, 51]]),
 array([[ 9, 12, 15],
        [36, 39, 42],
        [63, 66, 69]]),
 array([[ 3, 12, 21],
        [30, 39, 48],
        [57, 66, 75]]))
0

Thông tin về bố cục bộ nhớ của mảng.

>>> x = np.arange(27).reshape((3,3,3))
>>> x
array([[[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8]],
       [[ 9, 10, 11],
        [12, 13, 14],
        [15, 16, 17]],
       [[18, 19, 20],
        [21, 22, 23],
        [24, 25, 26]]])
>>> x.sum(axis=0)
array([[27, 30, 33],
       [36, 39, 42],
       [45, 48, 51]])
>>> # for sum, axis is the first keyword, so we may omit it,
>>> # specifying only its value
>>> x.sum(0), x.sum(1), x.sum(2)
(array([[27, 30, 33],
        [36, 39, 42],
        [45, 48, 51]]),
 array([[ 9, 12, 15],
        [36, 39, 42],
        [63, 66, 69]]),
 array([[ 3, 12, 21],
        [30, 39, 48],
        [57, 66, 75]]))
1

Tuple của kích thước mảng.

>>> x = np.arange(27).reshape((3,3,3))
>>> x
array([[[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8]],
       [[ 9, 10, 11],
        [12, 13, 14],
        [15, 16, 17]],
       [[18, 19, 20],
        [21, 22, 23],
        [24, 25, 26]]])
>>> x.sum(axis=0)
array([[27, 30, 33],
       [36, 39, 42],
       [45, 48, 51]])
>>> # for sum, axis is the first keyword, so we may omit it,
>>> # specifying only its value
>>> x.sum(0), x.sum(1), x.sum(2)
(array([[27, 30, 33],
        [36, 39, 42],
        [45, 48, 51]]),
 array([[ 9, 12, 15],
        [36, 39, 42],
        [63, 66, 69]]),
 array([[ 3, 12, 21],
        [30, 39, 48],
        [57, 66, 75]]))
2

Tuple của byte để bước trong mỗi chiều khi đi qua một mảng.

>>> x = np.arange(27).reshape((3,3,3))
>>> x
array([[[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8]],
       [[ 9, 10, 11],
        [12, 13, 14],
        [15, 16, 17]],
       [[18, 19, 20],
        [21, 22, 23],
        [24, 25, 26]]])
>>> x.sum(axis=0)
array([[27, 30, 33],
       [36, 39, 42],
       [45, 48, 51]])
>>> # for sum, axis is the first keyword, so we may omit it,
>>> # specifying only its value
>>> x.sum(0), x.sum(1), x.sum(2)
(array([[27, 30, 33],
        [36, 39, 42],
        [45, 48, 51]]),
 array([[ 9, 12, 15],
        [36, 39, 42],
        [63, 66, 69]]),
 array([[ 3, 12, 21],
        [30, 39, 48],
        [57, 66, 75]]))
3

Số lượng kích thước mảng.

>>> x = np.arange(27).reshape((3,3,3))
>>> x
array([[[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8]],
       [[ 9, 10, 11],
        [12, 13, 14],
        [15, 16, 17]],
       [[18, 19, 20],
        [21, 22, 23],
        [24, 25, 26]]])
>>> x.sum(axis=0)
array([[27, 30, 33],
       [36, 39, 42],
       [45, 48, 51]])
>>> # for sum, axis is the first keyword, so we may omit it,
>>> # specifying only its value
>>> x.sum(0), x.sum(1), x.sum(2)
(array([[27, 30, 33],
        [36, 39, 42],
        [45, 48, 51]]),
 array([[ 9, 12, 15],
        [36, 39, 42],
        [63, 66, 69]]),
 array([[ 3, 12, 21],
        [30, 39, 48],
        [57, 66, 75]]))
4

Đối tượng bộ đệm Python trỏ đến đầu dữ liệu của mảng.

>>> x = np.arange(27).reshape((3,3,3))
>>> x
array([[[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8]],
       [[ 9, 10, 11],
        [12, 13, 14],
        [15, 16, 17]],
       [[18, 19, 20],
        [21, 22, 23],
        [24, 25, 26]]])
>>> x.sum(axis=0)
array([[27, 30, 33],
       [36, 39, 42],
       [45, 48, 51]])
>>> # for sum, axis is the first keyword, so we may omit it,
>>> # specifying only its value
>>> x.sum(0), x.sum(1), x.sum(2)
(array([[27, 30, 33],
        [36, 39, 42],
        [45, 48, 51]]),
 array([[ 9, 12, 15],
        [36, 39, 42],
        [63, 66, 69]]),
 array([[ 3, 12, 21],
        [30, 39, 48],
        [57, 66, 75]]))
5

Số lượng các yếu tố trong mảng.

>>> x = np.arange(27).reshape((3,3,3))
>>> x
array([[[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8]],
       [[ 9, 10, 11],
        [12, 13, 14],
        [15, 16, 17]],
       [[18, 19, 20],
        [21, 22, 23],
        [24, 25, 26]]])
>>> x.sum(axis=0)
array([[27, 30, 33],
       [36, 39, 42],
       [45, 48, 51]])
>>> # for sum, axis is the first keyword, so we may omit it,
>>> # specifying only its value
>>> x.sum(0), x.sum(1), x.sum(2)
(array([[27, 30, 33],
        [36, 39, 42],
        [45, 48, 51]]),
 array([[ 9, 12, 15],
        [36, 39, 42],
        [63, 66, 69]]),
 array([[ 3, 12, 21],
        [30, 39, 48],
        [57, 66, 75]]))
6

Chiều dài của một phần tử mảng trong byte.

>>> x = np.arange(27).reshape((3,3,3))
>>> x
array([[[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8]],
       [[ 9, 10, 11],
        [12, 13, 14],
        [15, 16, 17]],
       [[18, 19, 20],
        [21, 22, 23],
        [24, 25, 26]]])
>>> x.sum(axis=0)
array([[27, 30, 33],
       [36, 39, 42],
       [45, 48, 51]])
>>> # for sum, axis is the first keyword, so we may omit it,
>>> # specifying only its value
>>> x.sum(0), x.sum(1), x.sum(2)
(array([[27, 30, 33],
        [36, 39, 42],
        [45, 48, 51]]),
 array([[ 9, 12, 15],
        [36, 39, 42],
        [63, 66, 69]]),
 array([[ 3, 12, 21],
        [30, 39, 48],
        [57, 66, 75]]))
7

Tổng số byte được tiêu thụ bởi các yếu tố của mảng.

>>> x = np.arange(27).reshape((3,3,3))
>>> x
array([[[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8]],
       [[ 9, 10, 11],
        [12, 13, 14],
        [15, 16, 17]],
       [[18, 19, 20],
        [21, 22, 23],
        [24, 25, 26]]])
>>> x.sum(axis=0)
array([[27, 30, 33],
       [36, 39, 42],
       [45, 48, 51]])
>>> # for sum, axis is the first keyword, so we may omit it,
>>> # specifying only its value
>>> x.sum(0), x.sum(1), x.sum(2)
(array([[27, 30, 33],
        [36, 39, 42],
        [45, 48, 51]]),
 array([[ 9, 12, 15],
        [36, 39, 42],
        [63, 66, 69]]),
 array([[ 3, 12, 21],
        [30, 39, 48],
        [57, 66, 75]]))
8

Đối tượng cơ sở nếu bộ nhớ là từ một số đối tượng khác.

Loại dữ liệu#

Đối tượng kiểu dữ liệu được liên kết với mảng có thể được tìm thấy trong thuộc tính

>>> x = np.arange(27).reshape((3,3,3))
>>> x
array([[[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8]],
       [[ 9, 10, 11],
        [12, 13, 14],
        [15, 16, 17]],
       [[18, 19, 20],
        [21, 22, 23],
        [24, 25, 26]]])
>>> x.sum(axis=0)
array([[27, 30, 33],
       [36, 39, 42],
       [45, 48, 51]])
>>> # for sum, axis is the first keyword, so we may omit it,
>>> # specifying only its value
>>> x.sum(0), x.sum(1), x.sum(2)
(array([[27, 30, 33],
        [36, 39, 42],
        [45, 48, 51]]),
 array([[ 9, 12, 15],
        [36, 39, 42],
        [63, 66, 69]]),
 array([[ 3, 12, 21],
        [30, 39, 48],
        [57, 66, 75]]))
9:

ndarray0

Loại dữ liệu của các yếu tố của mảng.

Các thuộc tính khác#

ndarray1

Các mảng chuyển vị.

ndarray2

Phần thực của mảng.

ndarray3

Phần tưởng tượng của mảng.

ndarray4

Một trình lặp 1-D trên mảng.

Giao diện mảng#

ndarray5

Phía python của giao diện mảng

ndarray6

C-Side của giao diện mảng

ndarray7 Giao diện chức năng nước ngoài#

ndarray8

Một đối tượng để đơn giản hóa sự tương tác của mảng với mô -đun CTYPES.

Phương thức mảng#

Một đối tượng ndarray có nhiều phương thức hoạt động trên hoặc với mảng theo một số kiểu, thường trả về kết quả mảng. Những phương pháp này được giải thích ngắn gọn dưới đây. (Mỗi phương thức DocString có một mô tả đầy đủ hơn.)

Đối với các phương pháp sau đây cũng có các hàm tương ứng trong shape0: shape1, shape2, shape3, shape4, shape5, shape6, shape7 ndarray0, ndarray1, ndarray2, ndarray3, ndarray4, ndarray5, ndarray6, ndarray7, ndarray8, ndarray9, ndarray0, ndarray1, ____.

Chuyển đổi mảng#

ndarray8(*args)

Sao chép một phần tử của một mảng vào vô hướng Python tiêu chuẩn và trả lại nó.

ndarray9()

Trả lại mảng dưới dạng danh sách lồng sâu của ____ 90 cấp độ của vô hướng Python.

ndarrays1(*args)

Chèn vô hướng vào một mảng (vô hướng được đúc vào dtype của mảng, nếu có thể)

ndarrays2([order])

Một bí danh tương thích cho Tobytes, với chính xác hành vi tương tự.

ndarrays3([order])

Xây dựng byte python chứa các byte dữ liệu thô trong mảng.

ndarrays4(fid[, sep, format])

Viết mảng vào một tệp dưới dạng văn bản hoặc nhị phân (mặc định).

ndarrays5(file)

Đổ một dưa chua của mảng vào tệp được chỉ định.

ndarrays6()

Trả về dưa chua của mảng dưới dạng chuỗi.

ndarrays7(dtype[, order, casting, ...])

Bản sao của mảng, đúc vào một loại được chỉ định.

ndarrays8([inplace])

Trao đổi byte của các phần tử mảng

ndarrays9([order])

Trả về một bản sao của mảng.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
00([dtype][, type])

Chế độ xem mới của mảng với cùng một dữ liệu.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
01(dtype[, offset])

Trả về một trường của mảng đã cho dưới dạng một loại nhất định.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
02([write, align, uic])

Đặt các cờ mảng có thể ghi, căn chỉnh, writeBackifcopy, tương ứng.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
03(value)

Điền vào mảng với giá trị vô hướng.

Thao tác hình dạng#

Để định hình lại, thay đổi kích thước và chuyển vị, đối số tuple duy nhất có thể được thay thế bằng các số nguyên

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
04 sẽ được hiểu là một n-tuple.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
05(shape[, order])

Trả về một mảng chứa cùng một dữ liệu với hình dạng mới.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
06(new_shape[, refcheck])

Thay đổi hình dạng và kích thước của mảng tại chỗ.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
07(*axes)

Trả về một chế độ xem của mảng với các trục được chuyển đổi.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
08(axis1, axis2)

Trả về một chế độ xem của mảng với Axis1 và Axis2 hoán đổi cho nhau.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
09([order])

Trả lại một bản sao của mảng bị sụp đổ thành một chiều.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
10([order])

Trả lại một mảng phẳng.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
11([axis])

Tháo trục có độ dài một từ a.

Lựa chọn và thao tác mục#

Đối với các phương thức mảng lấy từ khóa trục, nó mặc định là không có. Nếu trục là không, thì mảng được coi là mảng 1-D. Bất kỳ giá trị nào khác cho trục đại diện cho kích thước mà hoạt động nên tiến hành.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
12(indices[, axis, out, mode])

Trả về một mảng được hình thành từ các yếu tố của A tại các chỉ số đã cho.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
13(indices, values[, mode])

Đặt

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
14 cho tất cả N trong các chỉ số.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
15(repeats[, axis])

Lặp lại các yếu tố của một mảng.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
16(choices[, out, mode])

Sử dụng một mảng chỉ mục để xây dựng một mảng mới từ một tập hợp các lựa chọn.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
17([axis, kind, order])

Sắp xếp một mảng tại chỗ.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
18([axis, kind, order])

Trả về các chỉ số sẽ sắp xếp mảng này.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
19(kth[, axis, kind, order])

Sắp xếp lại các phần tử trong mảng theo cách mà giá trị của phần tử ở vị trí KTH ở vị trí nó sẽ ở trong một mảng được sắp xếp.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
20(kth[, axis, kind, order])

Trả về các chỉ số sẽ phân vùng mảng này.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
21(v[, side, sorter])

Tìm các chỉ số trong đó các yếu tố của V nên được chèn vào A để duy trì thứ tự.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
22()

Trả về các chỉ số của các yếu tố khác không.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
23(condition[, axis, out])

Trả về các lát được chọn của mảng này dọc theo trục đã cho.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
24([offset, axis1, axis2])

Trả về các đường chéo được chỉ định.

Calculation#

Nhiều trong số các phương pháp này có một đối số có tên là trục. Trong trường hợp này,

  • Nếu trục không (mặc định), mảng được coi là mảng 1-D và thao tác được thực hiện trên toàn bộ mảng. Hành vi này cũng là mặc định nếu bản thân là một mảng 0 chiều hoặc vô hướng mảng. .

  • Nếu trục là một số nguyên, thì thao tác được thực hiện trên trục đã cho (đối với mỗi subarray 1 chiều có thể được tạo dọc theo trục đã cho).

Ví dụ về đối số trục

Một mảng 3 chiều có kích thước 3 x 3 x 3, được tổng hợp trên mỗi ba trục của nó

>>> x = np.arange(27).reshape((3,3,3))
>>> x
array([[[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8]],
       [[ 9, 10, 11],
        [12, 13, 14],
        [15, 16, 17]],
       [[18, 19, 20],
        [21, 22, 23],
        [24, 25, 26]]])
>>> x.sum(axis=0)
array([[27, 30, 33],
       [36, 39, 42],
       [45, 48, 51]])
>>> # for sum, axis is the first keyword, so we may omit it,
>>> # specifying only its value
>>> x.sum(0), x.sum(1), x.sum(2)
(array([[27, 30, 33],
        [36, 39, 42],
        [45, 48, 51]]),
 array([[ 9, 12, 15],
        [36, 39, 42],
        [63, 66, 69]]),
 array([[ 3, 12, 21],
        [30, 39, 48],
        [57, 66, 75]]))

Tham số DTYPE chỉ định loại dữ liệu mà một hoạt động giảm (như tổng hợp) sẽ diễn ra. Kiểu giảm dữ liệu mặc định giống như kiểu dữ liệu của bản thân. Để tránh tràn, có thể hữu ích để thực hiện giảm bằng cách sử dụng loại dữ liệu lớn hơn.

Đối với một số phương pháp, một đối số tùy chọn cũng có thể được cung cấp và kết quả sẽ được đặt vào mảng đầu ra được đưa ra. Đối số ra phải là một ndarray và có cùng số lượng các yếu tố. Nó có thể có một loại dữ liệu khác nhau trong trường hợp đúc sẽ được thực hiện.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
26([axis, out, keepdims, initial, ...])

Trả lại tối đa dọc theo một trục nhất định.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
27([axis, out, keepdims])

Trả về các chỉ số của các giá trị tối đa dọc theo trục đã cho.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
28([axis, out, keepdims, initial, ...])

Trả lại tối thiểu dọc theo một trục nhất định.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
29([axis, out, keepdims])

Trả về các chỉ số của các giá trị tối thiểu dọc theo trục đã cho.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
30([axis, out, keepdims])

Giá trị cực đại đến cực đại (tối đa - tối thiểu) dọc theo một trục đã cho.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
31([min, max, out])

Trả về một mảng có giá trị được giới hạn ở

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
32.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
33()

Liên kết phức tạp tất cả các yếu tố.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
34([decimals, out])

Trả lại A với mỗi phần tử được làm tròn cho số thập phân đã cho.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
35([offset, axis1, axis2, dtype, out])

Trả lại tổng dọc theo các đường chéo của mảng.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
36([axis, dtype, out, keepdims, ...])

Trả về tổng của các phần tử mảng trên trục đã cho.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
37([axis, dtype, out])

Trả về tổng tích lũy của các phần tử dọc theo trục đã cho.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
38([axis, dtype, out, keepdims, where])

Trả về trung bình của các phần tử mảng dọc theo trục đã cho.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
39([axis, dtype, out, ddof, ...])

Trả về phương sai của các phần tử mảng, dọc theo trục đã cho.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
40([axis, dtype, out, ddof, ...])

Trả về độ lệch chuẩn của các phần tử mảng dọc theo trục đã cho.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
41([axis, dtype, out, keepdims, ...])

Trả lại sản phẩm của các phần tử mảng qua trục đã cho

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
42([axis, dtype, out])

Trả lại sản phẩm tích lũy của các phần tử dọc theo trục đã cho.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
43([axis, out, keepdims, where])

Trả về true nếu tất cả các yếu tố đánh giá đúng.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
44([axis, out, keepdims, where])

Trả về đúng nếu bất kỳ yếu tố nào của một đánh giá cho đúng.

Số học, phép nhân ma trận và các hoạt động so sánh#

Các hoạt động số học và so sánh trên ndarrays được định nghĩa là các hoạt động của phần tử khôn ngoan và thường mang lại các đối tượng ndarray làm kết quả.

Each of the arithmetic operations (

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
47,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
48,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
49,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
50,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
51,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
52,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
53,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
54 or
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
55,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
56,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
57,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
58,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
59,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
60,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
61) and the comparisons (
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
62,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
63,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
64,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
65,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
66,
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
67) tương đương với hàm phổ quát tương ứng (hoặc ngắn gọn Ufunc) trong Numpy. Để biết thêm thông tin, xem phần về các chức năng phổ quát.ufunc for short) in NumPy. For more information, see the section on Universal Functions.

Toán tử so sánh:

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
68(value, /)

Tự trả lại

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
69(value, /)

Tự trả lại

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
70(value, /)

Tự trả lại> giá trị.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
71(value, /)

Tự trả lại> = giá trị.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
72(value, /)

Tự trả lại == giá trị.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
73(value, /)

Tự trả lại! = Giá trị.

Giá trị sự thật của một mảng (

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
74):

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
75(/)

Đúng nếu tự sai

Ghi chú

Kiểm tra giá trị sự thật của một mảng gọi

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
75, gây ra lỗi nếu số lượng phần tử trong mảng lớn hơn 1, bởi vì giá trị sự thật của các mảng đó là mơ hồ. Thay vào đó, sử dụng
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
77 và
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
78 để rõ ràng về những gì có nghĩa là trong những trường hợp như vậy. (Nếu số lượng phần tử là 0, mảng sẽ đánh giá thành
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
79.)

Hoạt động đơn:

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
80(/)

-self

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
81(/)

+self

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
82(self)

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
83(/)

~self

Arithmetic:

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
84(value, /)

Trả lại giá trị tự+.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
85(value, /)

Trả lại giá trị tự.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
86(value, /)

Trả lại giá trị tự*.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
87(value, /)

Trả lại bản thân/giá trị.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
88(value, /)

Tự trả lại // giá trị.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
89(value, /)

Trả lại giá trị%tự.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
90(value, /)

Trả về divmod (tự, giá trị).

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
91(value[, mod])

Trả lại pow (tự, giá trị, mod).

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
92(value, /)

Tự trả lại

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
93(value, /)

Tự trả lại> giá trị.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
94(value, /)

Tự trả lại> = giá trị.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
95(value, /)

Tự trả lại == giá trị.

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
96(value, /)

Tự trả lại! = Giá trị.

Ghi chú

  • Kiểm tra giá trị sự thật của một mảng gọi

    >>> # The element of x in the *second* row, *third* column, namely, 6.
    >>> x[1, 2]
    6
    
    75, gây ra lỗi nếu số lượng phần tử trong mảng lớn hơn 1, bởi vì giá trị sự thật của các mảng đó là mơ hồ. Thay vào đó, sử dụng
    >>> # The element of x in the *second* row, *third* column, namely, 6.
    >>> x[1, 2]
    6
    
    77 và
    >>> # The element of x in the *second* row, *third* column, namely, 6.
    >>> x[1, 2]
    6
    
    78 để rõ ràng về những gì có nghĩa là trong những trường hợp như vậy. (Nếu số lượng phần tử là 0, mảng sẽ đánh giá thành
    >>> # The element of x in the *second* row, *third* column, namely, 6.
    >>> x[1, 2]
    6
    
    79.)

  • Hoạt động đơn:

  • Trả lại giá trị tự+.

Trả lại giá trị tự.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
02(value, /)

Trả lại giá trị tự*.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
03(value, /)

Trả lại bản thân/giá trị.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
04(value, /)

Tự trả lại // giá trị.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
05(value, /)

Trả lại giá trị%tự.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
06(value, /)

Trả về divmod (tự, giá trị).

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
07(value, /)

Trả lại pow (tự, giá trị, mod).

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
08(value, /)

Tự trả lại >> giá trị.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
09(value, /)

Tự trả lại

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
10(value, /)

Tự trả lại> giá trị.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
11(value, /)

Tự trả lại> = giá trị.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
12(value, /)

Tự trả lại == giá trị.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
13(value, /)

Tự trả lại! = Giá trị.

Giá trị sự thật của một mảng (

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
74):

Đúng nếu tự sai

Ghi chú

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
23(value, /)

Kiểm tra giá trị sự thật của một mảng gọi

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
75, gây ra lỗi nếu số lượng phần tử trong mảng lớn hơn 1, bởi vì giá trị sự thật của các mảng đó là mơ hồ. Thay vào đó, sử dụng
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
77 và
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
78 để rõ ràng về những gì có nghĩa là trong những trường hợp như vậy. (Nếu số lượng phần tử là 0, mảng sẽ đánh giá thành
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
79.)@value.

Ghi chú

Kiểm tra giá trị sự thật của một mảng gọi

>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
75, gây ra lỗi nếu số lượng phần tử trong mảng lớn hơn 1, bởi vì giá trị sự thật của các mảng đó là mơ hồ. Thay vào đó, sử dụng
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
77 và
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
78 để rõ ràng về những gì có nghĩa là trong những trường hợp như vậy. (Nếu số lượng phần tử là 0, mảng sẽ đánh giá thành
>>> # The element of x in the *second* row, *third* column, namely, 6.
>>> x[1, 2]
6
79.)PEP 465, and the
>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
24 operator has been introduced in NumPy 1.10.0. Further information can be found in the
>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
27 documentation.

Hoạt động đơn:

Trả lại giá trị tự+.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
28()

Trả lại giá trị tự.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
30(memo, /)

Trả lại giá trị tự*.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
32()

Trả lại bản thân/giá trị.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
33(state, /)

Tự trả lại // giá trị.

Trả lại giá trị%tự.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
34(*args, **kwargs)

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
35([dtype], /)

Trả về divmod (tự, giá trị).

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
36(array[, context], /)

Trả lại pow (tự, giá trị, mod).

Tùy chỉnh container: (xem lập chỉ mục)Indexing)

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
38(/)

Trả lại Len (tự).

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
39(key, /)

Tự trả lại [khóa].

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
40(key, value, /)

Đặt bản thân [khóa] thành giá trị.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
41(key, /)

Trả lại khóa trong bản thân.

Chuyển đổi;Các hoạt động

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
42,
>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
43 và
>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
44.Chúng chỉ làm việc trên các mảng có một yếu tố trong đó và trả lại vô hướng thích hợp.

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
45(self)

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
46(self)

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
47

Đại diện chuỗi:

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
48(/)

Trả lại str (tự).

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
49(/)

Trả lại repr (tự).

Phương pháp tiện ích để gõ:

>>> y = x[:,1]
>>> y
array([2, 5], dtype=int32)
>>> y[0] = 9 # this also changes the corresponding element in x
>>> y
array([9, 5], dtype=int32)
>>> x
array([[1, 9, 3],
       [4, 5, 6]], dtype=int32)
50(item, /)

Trả về một trình bao bọc tham số xung quanh loại ndarray.