Hướng dẫn can we subtract two arrays in python? - chúng ta có thể trừ hai mảng trong python không?

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Cải thiện bài viết

    Lưu bài viết

    Đọc function is used when we want to compute the difference of two array.It returns the difference of arr1 and arr2, element-wise.

    Bàn luận numpy.subtract(arr1, arr2, /, out=None, *, where=True, casting=’same_kind’, order=’K’, dtype=None, subok=True[, signature, extobj], ufunc ‘subtract’)

    Hàm numpy.subtract() được sử dụng khi chúng ta muốn tính toán chênh lệch của hai mảng. Nó trả về sự khác biệt của ARR1 và ARR2, phần tử khôn ngoan.
    arr1 : [array_like or scalar]1st Input array.
    arr2 : [array_like or scalar]2nd Input array.
    dtype : The type of the returned array. By default, the dtype of arr is used.
    out : [ndarray, optional] A location into which the result is stored.
      -> If provided, it must have a shape that the inputs broadcast to.
      -> If not provided or None, a freshly-allocated array is returned.
    where : [array_like, optional] Values of True indicate to calculate the ufunc at that position, values of False indicate to leave the value in the output alone.
    **kwargs : Allows to pass keyword variable length of argument to a function. Used when we want to handle named argument in a function.

    Cú pháp: numpy.subTract (ARR1, ARR2, /, OUT = Không, *, trong đó = true, casting = 'giống nhau_kind', order = 'k', dtype = none, subok = true [ Trừ ') [ndarray or scalar] The difference of arr1 and arr2, element-wise. Returns a scalar if both arr1 and arr2 are scalars.

    Tham số: ARR1: [Array_Lhe hoặc Scalar] Mảng đầu vào đầu tiên.Arr2: [Array_Lhe hoặc Scalar] Mảng đầu vào thứ 2.DTYPE: Loại của mảng được trả về. Theo mặc định, DTYPE của ARR được sử dụng. -> Nếu không được cung cấp hoặc không có, một mảng mới được phân bổ được trả về. Ở đâu: [Array_Like, Tùy chọn] Các giá trị của True cho biết để tính toán UFUNC ở vị trí đó, các giá trị của sai chỉ ra giá trị trong đầu ra. ** KWARGS: Cho phép chuyển độ dài biến từ khóa của đối số cho một hàm. Được sử dụng khi chúng tôi muốn xử lý đối số được đặt tên trong một hàm.

    Trả về: [Ndarray hoặc vô hướng] Sự khác biệt của ARR1 và ARR2, phần tử khôn ngoan. Trả về vô hướng nếu cả ARR1 và ARR2 là vô hướng.

    Mã số 1:

    import numpy as geek

    in_num1 ____10

    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    1

    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    2
    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    0
    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    4

    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    5
    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    6
    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    7
    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    8

    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    5
    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    6
    numpy.subtract(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = 
    
    1
    numpy.subtract(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = 
    
    2

    numpy.subtract(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = 
    
    3
    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    0
    numpy.subtract(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = 
    
    5

    1st Input number :  4
    2nd Input number :  6
    Difference of two input number :  -2
    

    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    5
    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    6
    numpy.subtract(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = 
    
    8
    numpy.subtract(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = 
    
    9

    Trả về: [Ndarray hoặc vô hướng] Sự khác biệt của ARR1 và ARR2, phần tử khôn ngoan. Trả về vô hướng nếu cả ARR1 và ARR2 là vô hướng.

    Mã số 1:

    import numpy as geek

    in_num1 ____10

    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    1

    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    2
    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    0
    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    4

    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    5
    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    6
    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    7
    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    8

    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    5
    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    6
    numpy.subtract(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = 
    
    1
    numpy.subtract(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = 
    
    2

    numpy.subtract(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = 
    
    3
    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    
    0
    numpy.subtract(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = 
    
    5

    1st Input array :  [[ 2 -4  5]
     [-6  2  0]]
    2nd Input array :  [[ 0 -7  5]
     [ 5 -2  9]]
    Output array:  [[  2   3   0]
     [-11   4  -9]]
    
    


    Umme ammara

    Bản quyền © 2022 Giáo dục, Inc. Tất cả quyền được bảo lưunumpy.subtract() method subtracts two arrays element-wise.

    Bạn có thể trừ hai mảng trong Python không?

    Phương thức Numpy.SubTract () của Python trừ hai phần tử khôn ngoan.

    numpy.subtract(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = 
    

    Bạn có thể trừ trong Python?universal function (ufunc) is a function that operates on ndarrays in an element-by-element fashion. The numpy as geek3 method is a universal function.

    Trong Python, các toán tử bổ sung và trừ thực hiện tương tự như toán học. Trên thực tế, bạn có thể sử dụng ngôn ngữ lập trình Python làm máy tính.

    Bạn có thể kết hợp hai mảng trong Python không?

    • Làm thế nào để kết hợp các mảng numpy trong Python? Bạn có thể sử dụng hàm numpy.concatenate () để kết hợp, hợp nhất hoặc tham gia một chuỗi hai hoặc nhiều mảng thành một mảng numpy. Kết nối đề cập đến việc đặt nội dung của hai hoặc nhiều mảng trong một mảng. and numpy as geek6 [array-like] - arrays that need to be subtracted. If the shapethe shape of an array is the number of elements in each dimension of numpy as geek5 and numpy as geek6 is different, they must be broadcastable to a common shape for representing the output.

    Phương thức numpy.subtract() lấy các tham số tùy chọn sau:

    Giá trị trả về

    numpy.subtract() Trả về sự khác biệt của hai phần tử mảng khôn ngoan. Loại trả về là in_num1 1 hoặc in_num1 2 tùy thuộc vào loại đầu vào.

    Ví dụ

    Các ví dụ dưới đây cho thấy các cách khác nhau numpy.subtract() được sử dụng trong Python.

    Phép trừ hai số

    Mã dưới đây cho thấy sự khác biệt của hai số, 17,5 và 12. Kết quả được hiển thị bên dưới:

    import numpy as np

    a = 17.5

    b = 12

    result = np.subtract(a,b)

    print (result)

    Phép trừ hai mảng

    Ví dụ dưới đây cho thấy kết quả trừ hai mảng in_num1 4 và in_num1 5:

    import numpy as np

    arr1 = np.array([20,30,40])

    arr2 = np.array([2,3,4])

    result = np.subtract(arr1,arr2)

    print (result)

    Ví dụ dưới đây cho thấy kết quả trừ hai mảng in_num1 6 và in_num1 7:

    import numpy as np

    arr3 = np.array([[20,30,40], [-2,-3,-4]])

    arr4 = np.array([[-2,-3,-4], [30,40,50]])

    result = np.subtract(arr3,arr4)

    print (result)

    Người đóng góp

    Hướng dẫn can we subtract two arrays in python? - chúng ta có thể trừ hai mảng trong python không?
    Umme ammara

    Bản quyền © 2022 Giáo dục, Inc. Tất cả quyền được bảo lưu

    Bạn có thể trừ hai mảng trong Python không?

    Phương thức Numpy.SubTract () của Python trừ hai phần tử khôn ngoan. subtract() method subtracts two arrays element-wise.

    Bạn có thể trừ trong Python?

    Trong Python, các toán tử bổ sung và trừ thực hiện tương tự như toán học.Trên thực tế, bạn có thể sử dụng ngôn ngữ lập trình Python làm máy tính.addition and subtraction operators perform similarly to mathematics. In fact, you can use the Python programming language as a calculator.

    Bạn có thể kết hợp hai mảng trong Python không?

    Làm thế nào để kết hợp các mảng numpy trong Python?Bạn có thể sử dụng hàm numpy.concatenate () để kết hợp, hợp nhất hoặc tham gia một chuỗi hai hoặc nhiều mảng thành một mảng numpy.Kết nối đề cập đến việc đặt nội dung của hai hoặc nhiều mảng trong một mảng.You can use the numpy. concatenate() function to concat, merge, or join a sequence of two or multiple arrays into a single NumPy array. Concatenation refers to putting the contents of two or more arrays in a single array.

    Chúng ta có thể trừ hai chuỗi trong Python không?

    Bạn có thể trừ 2 chuỗi trong Python không?Chuỗi Python không có toán tử trừ.The Python string doesn't have a subtraction operator.