Home  >  Article  >  Backend Development  >  python code example of shape calculation matrix

python code example of shape calculation matrix

Y2J
Y2JOriginal
2017-05-03 16:07:291686browse

This article mainly introduces the method of shape calculation matrix in Python, involving the implementation skills related to Python mathematical operations. Friends in need can refer to the following

The example of this article describes the method of shape calculation matrix in Python. Share it with everyone for your reference, the details are as follows:

When I saw the machine learning algorithm, I noticed the method of calculating the matrix by shape. Next, let me talk about my understanding.

>>> from numpy import *
>>> import operator
>>> a =mat([[1,2,3],[5,6,9]])
>>> a
matrix([[1, 2, 3],
    [5, 6, 9]])
>>> shape(a)
(2, 3)
>>> a.shape[0] #计算行数
2
>>> a.shape[1] #计算列数
3

Next is Python Explanation in

Examples
--------
>>> np.shape(np.eye(3))
(3, 3)
>>> np.shape([[1, 2]])
(1, 2)
>>> np.shape([0])
(1,)
>>> np.shape(0)
()
>>> a = np.array([(1, 2), (3, 4)], dtype=[('x', 'i4'), ('y', 'i4')])
>>> np.shape(a)
(2,)
>>> a.shape
(2,)

The above is the detailed content of python code example of shape calculation matrix. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn