python code example of shape calculation matrix

Y2J
Release: 2017-05-03 16:07:29
Original
1752 people have browsed it

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]])
Copy after login
>>> shape(a)
(2, 3)
>>> a.shape[0] #计算行数
2
>>> a.shape[1] #计算列数
3
Copy after login

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,)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template