In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.