What does np do in python

In python, "np" generally refers to the "numpy" library, which is an alias for the third-party library "numpy". Method: Use the command "import numpy as np" to alias the numpy library as "np".

Demo:

import numpy as np
arr = np.array([1,2,3])print(arr)

The result is:

[123]

Knowledge point expansion:

Basic use of NumPy in Python

ndarray (hereinafter referred to as array) is a numpy array object. It should be noted that it is isomorphic, which means that all elements must be of the same type. Each of these arrays has a shape and dtype.

shape is the shape of the array, such as

import numpy as np
from numpy.random import randn

arr =randn(12).reshape(3,4)

arr

[[0.986552351.20830283-0.721351830.40292924][-0.05059849-0.02714873-0.627754860.83222997][-0.84826071-0.29484606-0.769849020.09025059]]

arr.shape(3,4)

(3, 4) means that arr is an array with 3 rows and 4 columns, where dtype is float64

The following function can be used to create an array

array Convert the input data to ndarray, the type can be specified or defaulted
asarray Convert input to ndarray
arange Similar to built-in range
ones, ones_like Create an array of all 1s according to the shape, the latter can copy the shape of other arrays
zeros, zeros_like similar to the above, all 0s
empty, empty_like Create a new array, only allocate space
eye, identity Create a diagonal matrix with a diagonal of 1

So far, this article about what np does in python is introduced here. For more information about what np in python is, please search for ZaLou.Cn's previous articles or continue to browse related articles below. Hope you will support more in the future ZaLou.Cn!

Recommended Posts

What does np do in python
What does def in python do
What does rc1 mean in python
What can Python do
What does the tab key in python mean
What can python collections do
What is introspection in python
What is object-oriented in python
What is list comprehension in python
​What are the numbers in Python?
What are web development frameworks in python
What is a sequence table in Python
What kind of work can python do
Functions in python
What is the function of adb in python
What conditions are needed for infinite loop in Python
Join function in Python
12. Network Programming in Python3
print statement in python
What software do I need to install to learn Python?
Install python in Ubuntu
Context management in Python
Arithmetic operators in python
Write gui in python
MongoDB usage in Python
Str string in Python
Computational Geometry in Python
What are the ways to open files in python
Do you still know how to draw cakes in python? ? ?
Concurrent requests in Python (part 2)
What are python class attributes
Subscripts of tuples in Python
How does Python output integers
How does python output backslashes
Talking about inheritance in Python
Noteworthy update points in Python 3.9
What databases can python use
Does Python support multiple inheritance?
Containerize Python applications in 3 minutes
How does python update packages
What is Python variable scope
Generators and iterators in Python
Talking about strings in Python