Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use numpy in Python

Shulou Source: shulou.com Published: 2022-06-01 19:40:03 09月15日 Update

This article mainly shows you "how to use numpy in Python", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to use numpy in Python" this article.

Basic operation of 1.numpy

#! / usr/bin/env python

# coding:utf-8

Import numpy as np

Array = np.array ([[1, 2, 3], [4, 5, 5, 6])

Print (array)

Print ('Dimension:', array.ndim) # has several lines

Print (array.shape) # (2,3) has several rows and columns

Print ('size:',array.size) # Total size

A = np.array ([2jing3jin4], dtype=np.int64) # define type int64

Print (a.dtype)

A = np.zeros ((3p4)) # defines a matrix with three rows and four columns, all of which are 0

A = np.ones ((3p4)) # generates a matrix with three rows and four columns with a value of 1

A = np.empty ((3p4)) # generates a matrix with three rows and four columns with a value of 0

A = np.arange (1 and 10) # generate a matrix with steps from 1 to 9 to 2

A = np.arange (10) # generates a matrix from 0 to 9

A = np.arange (12). Reshape (3p4) # generates a sequence of three rows and four columns

A = np.linspace (1pm 10jue 6). Reshape (2pm 3) # generates a 6 segment with 2 rows and 3 columns between 1 and 10

A = np.array ([10, 20, 30, 40])

B = np.arange (4) # generate a matrix of four digits between 0 and 3, that is, a matrix of four arrays between 0 and 3

Print (aformab) # print a matrix

Addition of print (a b) # matrices

Print (aMub) # Matrix correlation

Print (aqb) # matrix multiplication

Print (aplomb) # Matrix multiplier

2. Numpy matrix operation

C = np.sin (a) * 10 # take sin for each value in a, then multiply by 10, con, tan are all like this

Print (c)

Print (b)

Tags: Matrix generation sequence dimension transformation maximum minimum three two maximum index three lines iteration one line up and down between content copy value data Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Linux NVidia OPPO Reno vpn