The Python list matrix defines and uses the

Source: Internet
Author: User
Tags python list

In Python, unlike C, the C language uses any variable to define its type (int a = 1), and Python can directly assign a value without defining (A = 1). However, to use a matrix, it is also defined when you assign a value directly. (Do not know if you can read, do not understand, you can not see, see below directly.) )

1. Definition matrix

>>> Import NumPy
>>> Import NumPy as NP
>>> y=np.empty ([2,2],dtype=int) #表示定义一个2 the *2 matrix, which is an integral type

2. Definition List

Method One:

>>> l=[] #该定义的列表长度是未知的
>>> l.append (' a ') #用append函数加入数据
>>> L
[' A ']

Method Two:

>>> L=range (#该定义的列表长度是已知的)
>>> l[3]= ' a ' #可以用该种方法向列表中赋值
>>> L
[0, 1, 2, ' a ', 4, 5, 6, 7, 8, 9]

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.