In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge about the usage of multiplication and addition examples of matrix and array in numpy. Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. For array array
Multiply
It is the multiplication of the elements in the corresponding position:
X1 = np.array ([[1jue 2], [3,4]]) X2 = X1print X2*X1 [[14] [9 16]]
Add
Is the addition of the corresponding positions:
X1 = np.array ([[1jue 2], [3,4]]) X2 = X1print X2+X1 [[24] [68]]
two。 For matrix matrix
Multiply
Is the dot multiplication of the matrix:
X1 = np.matrix ([[1jue 2], [3,4]]) X2 = X1print X2*X1 [[7 10] [15 22]]
Add
There are two cases, the first is the same size of X1 and X2, that is, the addition of ordinary matrices, that is, the addition of corresponding positions:
X1 = np.matrix ([[1jue 2], [3,4]]) X2 = X1print X2+X1 [[24] [68]]
In the second case, X1 of nym1 + X2 of mechn1 (or vice versa), you get the matrix of nfolm:
X1 = np.matrix ([1rect 2rem 3]]) X2 = np.matrix ([1rect 2meme 3je 4]]). Tprint X2+X1 [[2 34] [3 45] [4 56] [5 6 7]]
3. Mixed use situation
There are a lot of mixed use of matrix and array operators in numpy, and the program can also pass, but this is not good, so try to use it according to the above principles.
If 2D array wants to perform matrix point multiplication, you can use np.dot (X1, X2).
If matrix wants to multiply the corresponding positions, you can use np.multiply (X2MagneX1)
This is the end of the introduction to the usage of multiplication and addition examples of matrix and array in numpy. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.