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!