Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the basis of numpy in Python data analysis

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Python data analysis of what is the basis of numpy, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

Preface

NumPy (Numerical Python for short) is the basic package for high-performance scientific computing and data analysis. One of the most important features of NumPy is its N-dimensional array object (ndarray), which is a fast and flexible big data collection container. Beginners may not understand the meaning of this sentence, which needs to be understood slowly. In short, know that numpy is the most important basic package for python data analysis. With numpy, you can use this array to perform some mathematical operations on the whole block of data, which is more efficient than the arrays and tuples that come with python, and its syntax is the same as the operation between variable elements, without the need for circular operations.

Why do you need numpy

Python uses loops to calculate multiple data by default, which is very time-consuming if there are many loops. To take a simple example, we want to calculate the value of 100000 random numbers. If the traditional programming needs to write a loop, it takes 2.2 seconds, and using the numpy data structure, we can do vectorization operation, no loop, only need 28.2ms to save a lot of time.

A = [1, b=np.array, 2, 3, 4, 5] how does a+1b+1a*10b*10 generate ndarray

The core of numpy is ndarray (n-dimensional array), a multidimensional array. The so-called data is a collection of the same type of data, such as 1000 numbers to form an array, 1000 characters to form an array. Numpy contains a number of functions that can easily convert python data structures into numpy's ndarray.

A = [1, b=np.array 2, 3, 4, 5] a+1b+1a*10b*10

Compare the difference between traditional list array and ndarray

A = [1, b=np.array 2, 3, 4, 5] b=np.array ([1, 2, 3, 4, 5]) a+1b+1a*10b*10NumPy common functions

Numpy has many functions, among which the most common function of using numpy is to use it to produce numbers, such as random numbers, positive etheric distribution, arithmetic series and so on.

# use array to create an array: arr = np.array ([1mem2mage3]) arr = np.array ([1mem2mae3], [4mine5mem6], [7mae8] 9]) # create an array arr = np.arange using arange # create a two-dimensional array of 3 rows and 4 columns from 1 to 12 arr = np.arange (12). Reshape (3p4) # random generate random numbers # generate random number seed np.random.seed (1234) # randn generate positive etheric distribution sample np.random.randn (1000) # randomly generate integer dataset np.random.randint (size=1000,low=1,high=1000) mathematical calculation function

Numpy built in a lot of calculation functions, can do a lot of mathematics, the input data is a ndarray.

# create an array using array # x is a collection of 1000 random positive integers with values ranging from 1 to 1000. X=np.random.randint (size=1000,low=1,high=1000) # outputs xx# to calculate np.sum (x) np.mean (x) np.var (x) np.std (x) np.min (x) np.max (x) np.argmin (x) np.argmax (x) np.cumsum (x) np.cumprod (x) computer performance test

Let's do an interesting computer performance test, randomly generate a large data set to see how many bits your computer can calculate, which has something to do with memory.

# generate 1 million values to calculate x=np.random.randint (size=1000000,low=1,high=1000) np.sum (x) # generate 10 million values to calculate x=np.random.randint (size=10000000,low=1,high=1000) np.sum (x) # generate 100 million values to calculate x=np.random.randint (size=100000000,low=1,high=1000) np.sum (x) # if you think your computer performance is good, can you read the above content after the calculation challenge? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 251

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report