Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize the multiplication of Matrix corresponding elements by numpy

Shulou Source: shulou.com Published: 2022-06-01 07:51:25 09月28日 Update

This article mainly explains "numpy how to achieve matrix corresponding elements multiplication", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "numpy how to achieve matrix corresponding elements multiplication" bar!

1) matrix multiplication

Matrix multiplication: (m) n) x (n)-- > (m) p) # the premise of matrix multiplication: the column of matrix 1 = the row of matrix 2

Three uses: np.dot (matrix_a, matrix_b) = = matrix_a @ matrix_b = = matrix_a * matrix_b

2) element-wise product: multiply the corresponding elements of the matrix

1 usage: np.multiply (matrix_c, matrix_d)

For the nd.array () type, the array arrA * arrB can only be element-wise produt (multiplied by the corresponding elements)

#-*-coding: utf-8-* "Created on Thu Jul 26 14:22:40 2018@author: Administrator"import numpy as npa = np.array ([[1mai2], [3mae4], [11meme12]]) b = np.array ([[5miere 6mr13], [7mie 8mr14]]) c = np.array ([[1mie 2morie 13], [3pr 4pr 25], [11pr 12je 23]) d = np.array ([[5pr 6 mie 2], [7je 8mil 29]) ]) matrix_a = np.matrix (a) # (3pag2) matrix_b = np.matrix (b) # (2pime 3) matrix_c = np.matrix (c) # (3pian 3) matrix_d = np.matrix (d) # (3pint 3) print (type (a), type (matrix_a)) # mat_a = np.mat (a) print (type (a) Type (matrix_a)) #''# 1) matrix multiplication matrix multiplication: (MMagiere n) x (nQuery p)-- > (mLeary p) # Matrix multiplication operation premise: np.dot (matrix_a, matrix_b) = = matrix_a @ matrix_b = = matrix_a * matrix_b'''method_1 = matrix_a @ matrix_bmethod_2 = np.dot (matrix_a) Matrix_b) print (method_1) # [[19 22 41] # [43 50 95] # [139 162 311]] print (method_2 = = method_1) # [[True] # [True] # [True]] print (matrix_c * matrix_d = = matrix_c @ matrix_d) # [[True] # [True] # [True]]''# 2) element-wise product: Matrix correspondence 1 usage of multiplying elements: np.multiply (matrix_c Matrix_d) for the nd.array () type Array arrA * arrB can only element-wise produt (multiply the corresponding elements)''print (matrix_c, matrix_d, sep='\ n') # [[12 13] # [3 4 25] # [11 12 23]] # [[5 62] # [7 8 29] # [13 14 15]] method_1 = np.multiply (matrix_c Matrix_d) # Multiplication of corresponding position elements print (method_1) # [[5 12 26] # [21 32 725] # [143 168 345] 3) Matrix multiplication and array multiplication

Thank you for your reading, the above is the content of "how to achieve matrix corresponding element multiplication in numpy". After the study of this article, I believe you have a deeper understanding of how to achieve matrix corresponding element multiplication in numpy. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Matrix element multiplication array learning content premise type operation location that is ideas situations articles more knowledge knowledge points articles follow questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information Shulou Tech Info MariaDB Huawei