Hướng dẫn how to divide matrices in python - cách chia ma trận trong python
Chia đối số yếu tố khôn ngoan. Show Mảng cổ tức. x2array_likearray_likeMảng chia. Nếu Một vị trí mà kết quả được lưu trữ. Nếu được cung cấp, nó phải có một hình dạng mà các đầu vào phát só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ả lại. Một tuple (chỉ có thể là đối số từ khóa) phải có độ dài bằng số lượng đầu ra. wherearray_like, tùy chọnarray_like, optionalĐiều kiện này được phát trên đầu vào. Tại các vị trí mà điều kiện là đúng, mảng ra sẽ được đặt thành kết quả UFUNC. Ở những nơi khác, mảng ra sẽ giữ lại giá trị ban đầu của nó. Lưu ý rằng nếu một mảng ra không được tạo ra được tạo thông qua Đối với các đối số chỉ từ khóa khác, hãy xem các tài liệu UFUNC.ufunc docs. Returnsyndarray hoặc vô hướngyndarray or scalarThương số Xem thêm seterr Đặt nên nâng hay cảnh báo về tràn, tăng và phân chia theo số 0. Ghi chú Tương đương với >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])0 / >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])1 về mặt mảng-broadcasting. Hàm >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])2 là bí danh cho >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])3. Ví dụ >>> np.divide(2.0, 4.0) 0.5 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = np.arange(3.0) >>> np.divide(x1, x2) array([[nan, 1. , 1. ], [inf, 4. , 2.5], [inf, 7. , 4. ]]) Toán tử >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])4 có thể được sử dụng làm tốc ký cho >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])5 trên ndarrays. >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]]) chia ():- Hàm này được sử dụng để thực hiện phân chia ma trận yếu tố .. Làm thế nào để bạn chia một ma trận numpy?
Trở về : An array with arr1/arr2(element-wise) as elements of output array. & nbsp; mã 1: phân chia ARR1 cho các phần tử ARR2 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])6 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])7 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])8 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])9 An array with arr1/arr2(element-wise) as elements of output array.0 An array with arr1/arr2(element-wise) as elements of output array.1 An array with arr1/arr2(element-wise) as elements of output array.2223 An array with arr1/arr2(element-wise) as elements of output array.2221 An array with arr1/arr2(element-wise) as elements of output array.22272722222929 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 4, 5, 6] Output array : [ 1. 9. 0.5 4.2 3.83333333]1 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])9 An array with arr1/arr2(element-wise) as elements of output array.0 An array with arr1/arr2(element-wise) as elements of output array.1 An array with arr1/arr2(element-wise) as elements of output array.222222222222222222222222222222222 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]4 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]5 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]6 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]7 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]4 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]5 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 0, 5, 6] Output array : [ 1. 9. inf 4.2 3.83333333] RuntimeWarning: divide by zero encountered in true_divide out = np.power(arr1, arr2)0 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 0, 5, 6] Output array : [ 1. 9. inf 4.2 3.83333333] RuntimeWarning: divide by zero encountered in true_divide out = np.power(arr1, arr2)1 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 0, 5, 6] Output array : [ 1. 9. inf 4.2 3.83333333] RuntimeWarning: divide by zero encountered in true_divide out = np.power(arr1, arr2)2 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])9 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 0, 5, 6] Output array : [ 1. 9. inf 4.2 3.83333333] RuntimeWarning: divide by zero encountered in true_divide out = np.power(arr1, arr2)4 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]4 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]5 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 0, 5, 6] Output array : [ 1. 9. inf 4.2 3.83333333] RuntimeWarning: divide by zero encountered in true_divide out = np.power(arr1, arr2)7 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 0, 5, 6] Output array : [ 1. 9. inf 4.2 3.83333333] RuntimeWarning: divide by zero encountered in true_divide out = np.power(arr1, arr2)8 Đầu ra: arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 4, 5, 6] Output array : [ 1. 9. 0.5 4.2 3.83333333] & nbsp; Mã 2: Các yếu tố của ARR1 chia cho chia >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])6 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])7 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])8 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])9 An array with arr1/arr2(element-wise) as elements of output array.0 An array with arr1/arr2(element-wise) as elements of output array.1 An array with arr1/arr2(element-wise) as elements of output array.2223 An array with arr1/arr2(element-wise) as elements of output array.2221 An array with arr1/arr2(element-wise) as elements of output array.22272722222929 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 4, 5, 6] Output array : [ 1. 9. 0.5 4.2 3.83333333]1 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])9 An array with arr1/arr2(element-wise) as elements of output array.0 An array with arr1/arr2(element-wise) as elements of output array.1 An array with arr1/arr2(element-wise) as elements of output array.222222222222222222222222222222222 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]4 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]5 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]6 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]7 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]4 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]5 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 0, 5, 6] Output array : [ 1. 9. inf 4.2 3.83333333] RuntimeWarning: divide by zero encountered in true_divide out = np.power(arr1, arr2)0 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 0, 5, 6] Output array : [ 1. 9. inf 4.2 3.83333333] RuntimeWarning: divide by zero encountered in true_divide out = np.power(arr1, arr2)1 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]4 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]5 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 0, 5, 6] Output array : [ 1. 9. inf 4.2 3.83333333] RuntimeWarning: divide by zero encountered in true_divide out = np.power(arr1, arr2)7 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 0, 5, 6] Output array : [ 1. 9. inf 4.2 3.83333333] RuntimeWarning: divide by zero encountered in true_divide out = np.power(arr1, arr2)8 Đầu ra: arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667] & nbsp; Mã 2: Các yếu tố của ARR1 chia cho chia >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])6 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])7 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])8 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])9 An array with arr1/arr2(element-wise) as elements of output array.0 An array with arr1/arr2(element-wise) as elements of output array.1 An array with arr1/arr2(element-wise) as elements of output array.2223 An array with arr1/arr2(element-wise) as elements of output array.2221 An array with arr1/arr2(element-wise) as elements of output array.22272722222929 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 4, 5, 6] Output array : [ 1. 9. 0.5 4.2 3.83333333]1 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])9 An array with arr1/arr2(element-wise) as elements of output array.0 An array with arr1/arr2(element-wise) as elements of output array.1 An array with arr1/arr2(element-wise) as elements of output array.2222222222222 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]4 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]5 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]6 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]7 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]4 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]5 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 0, 5, 6] Output array : [ 1. 9. inf 4.2 3.83333333] RuntimeWarning: divide by zero encountered in true_divide out = np.power(arr1, arr2)0 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 0, 5, 6] Output array : [ 1. 9. inf 4.2 3.83333333] RuntimeWarning: divide by zero encountered in true_divide out = np.power(arr1, arr2)1 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 0, 5, 6] Output array : [ 1. 9. inf 4.2 3.83333333] RuntimeWarning: divide by zero encountered in true_divide out = np.power(arr1, arr2)2 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])9 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 0, 5, 6] Output array : [ 1. 9. inf 4.2 3.83333333] RuntimeWarning: divide by zero encountered in true_divide out = np.power(arr1, arr2)4 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]4 arr1 : [2, 27, 2, 21, 23] Output array : [ 0.66666667 9. 0.66666667 7. 7.66666667]5 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = 2 * np.ones(3) >>> x1 / x2 array([[0. , 0.5, 1. ], [1.5, 2. , 2.5], [3. , 3.5, 4. ]])29 arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 0, 5, 6] Output array : [ 1. 9. inf 4.2 3.83333333] RuntimeWarning: divide by zero encountered in true_divide out = np.power(arr1, arr2)8 Đầu ra: arr1 : [2, 27, 2, 21, 23] arr2 : [2, 3, 0, 5, 6] Output array : [ 1. 9. inf 4.2 3.83333333] RuntimeWarning: divide by zero encountered in true_divide out = np.power(arr1, arr2) Tài liệu tham khảo: https: //docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.divide.html. Làm thế nào để bạn chia một ma trận trong Python?Trong ma trận Python có thể được triển khai dưới dạng danh sách 2D hoặc mảng 2D ... Thêm ():- Hàm này được sử dụng để thực hiện bổ sung ma trận khôn ngoan .. Trừ ():- Hàm này được sử dụng để thực hiện phép trừ Ma trận khôn ngoan .. chia ():- Hàm này được sử dụng để thực hiện phân chia ma trận yếu tố .. Làm thế nào để bạn chia một ma trận numpy?Sử dụng hàm numpy.divide () để chia các phần tử mảng thứ nhất (ARR1) với các phần tử mảng thứ hai (ARR2).Cả ARR1 và ARR2 phải có cùng một hình dạng và phần tử trong ARR2 không được bằng không;Nếu không, nó sẽ gây ra lỗi. divide() function to divided the first array elements (arr1) with the second array elements (arr2). Both arr1 and arr2 must have the same shape and the element in arr2 must not be zero; otherwise, it will raise an error.
Làm thế nào để phân chia Numpy hoạt động?Phân chia là với hai mảng có cùng kích thước (nghĩa là các mảng có cùng số lượng hàng và cột).Nếu hai mảng đầu vào có cùng hình dạng, thì sự phân chia Numpy sẽ phân chia các phần tử của mảng thứ nhất cho các phần tử của mảng thứ hai, theo kiểu yếu tố khôn ngoan.If the two input arrays have the same shape, then Numpy divide will divide the elements of the first array by the elements of the second array, in an element-wise fashion.
Làm thế nào để bạn chia từng phần tử trong một ma trận cho một số trong Python?Để phân chia từng phần tử của một mảng cho một hằng số, hãy sử dụng toán tử số học phân chia /.Vượt qua mảng và hằng số dưới dạng toán hạng cho toán tử phân chia như được hiển thị bên dưới.trong đó A là mảng đầu vào và C là một hằng số.B là mảng kết quả.use division arithmetic operator / . Pass array and constant as operands to the division operator as shown below. where a is input array and c is a constant. b is the resultant array. |