Numpy attributes and matrix creation in python

不言
Release: 2018-09-08 16:56:53
Original
2171 people have browsed it

The content of this article is about the attributes and creation matrix of Numpy in python. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

ndarray.ndim: Dimension

ndarray.shape: Shape

ndarray.size: Number of elements

ndarray.dtype: Element data type

ndarray.itemsize: byte size

Create array:

a = np.array([2,23,4])  
# list 1d
print(a)
# [2 23 4]
Copy after login

Specify data type:

a = np.array([2,23,4],dtype=np.int)
print(a.dtype)
# int 64
Copy after login

dtype The types that can be specified are int32, float, float32, If not followed by a number, the default is 64

a = np.zeros((3,4)) # 数据全为0,3行4列
"""
Copy after login
a = np.ones((3,4),dtype = np.int)   # 数据为1,3行4列
Copy after login
a = np.empty((3,4)) # 数据为empty,3行4列
Copy after login

empty type: the initial content is random, depending on the state of the memory

a = np.arange(10,20,2) # 10-19 的数据,2步长
Copy after login
a = np.arange(12).reshape((3,4))    # 3行4列,0到11
Copy after login

reshape modifies the data shape, such as 3 rows and 4 columns

a = np.linspace(1,10,20)    # 开始端1,结束端10,且分割成20个数据,生成线段
Copy after login

linspace The amount of data can be determined, but arrage cannot determine the amount of data. At the same time, linspace can also use reshape to define the structure.

Related recommendations:

How to create a symmetric matrix in Python based on the numpy module

How does Python numpy extract the specified rows and columns of the matrix?

The above is the detailed content of Numpy attributes and matrix creation in python. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!