Python code example for shape calculation matrix

Source: Internet
Author: User
This article mainly introduces the method of shape computing matrix in Python, which involves the implementation of Python mathematical operations, and the need for a friend can refer to the following

This example describes the method of shape calculation matrix in Python. Share to everyone for your reference, as follows:

When you see the machine learning algorithm, you notice the shape calculation matrix. Now, let's talk about my understanding.

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

Next is the explanation in Python.

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 ')]) >>> n P.shape (a) (2,) >>> A.shape (2,)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.