In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article Xiaobian for you to introduce in detail "how to generate diagonal matrix numpy.diag", the content is detailed, the steps are clear, the details are handled properly, I hope this "how to generate diagonal matrix numpy.diag" article can help you solve your doubts, following the editor's ideas slowly in-depth, let's learn new knowledge.
Generate diagonal matrix numpy.diag
Given the diagonal elements, I want to generate a diagonal matrix. I searched the Internet and found that they were all numpy.diagonal.
The function of this function is to extract the diagonal elements of a given matrix, which is certainly not what I want.
Later, it was found that numpy.diag is the function that generates the diagonal matrix, so write this article to record it.
Import numpy as npa= [1Jing 2jue 3] np.diag (a) Out [4]: array ([[1, 0, 0], [0, 2, 0], [0, 0, 3]]) numpy.diag () structure and usage | | Parameter numpy.diag (vjingkus0)
Official document
Returns the diagonal (or non-diagonal) elements of a square matrix in the form of an one-dimensional array, or converts an one-dimensional array into a square matrix (non-diagonal elements are 0). The two functional role shifts depend on the v entered. one
For a deeper look, see numpy.diagnal ()
Detailed explanation of parameters
1.v:array_like.
If v is a 2D array, returns the diagonal of the k position.
If v is a 1D array, returns a two-dimensional array of v as the diagonal of the k position.
2.k:int, optional
The position of the diagonal, greater than zero is above the diagonal, and less than zero is below.
Example > x = np.arange (9). Reshape ((3p3)) > > xarray ([[0,1,2], [3,4,5], [6,7,8]]) > > np.diag (x) array ([0,4,8]) > np.diag (x, Kraft 1) array ([1,5]) > > np.diag (x, kink 1) array ([3,7]) > > np.diag (np.diag (x) array ([[0,0,0]) 0], [0,4,0], [0,0,8]) This article "how to generate diagonal matrix numpy.diag" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about the article, please follow the industry information channel.
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.