In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use Numpy's Anaconda". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use Numpy's Anaconda.
The basic usage of Anaconda
After installing Anaconda under windows, you can see the following components under Anaconda in all programs:
Anaconda Navigator: a graphical interface for managing toolkits and environments.
Anaconda Prompt: a command line interface for managing packages and environments.
Jupyter Note book: an interactive Web-based computing environment that demonstrates the process of data analysis and generates easy-to-read documents.
Spyder:Python integrated development environment, the layout is similar to Matlab.
We are mainly learning to use the third Jupyter Note book.
Here is a simple way to popularize the commonly used Anaconda commands (although I don't use them very often).
Check the software version number
Python-- version # View Python version
Conda-- version # View the version of conda
Add Mirror
Conda config-- add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
Update conda
Conda upgrade-all
View the installed packages
Conda list
Conda install [package name] # install package, installed in the default Python environment
It is recommended for beginners to install only Anaconda, which can save a lot of unnecessary trouble. the above is the basic use of Anaconda. You are welcome to add it in the message area.
Numpy index and slicing
Correct the mistakes in the previous article:
# correct import method
Import numpy as np
The index method of numpy is similar to the list index in Python. Here we mainly introduce the indexes / slices of ordinary array and Boolean array.
Index / slice of one-dimensional array
The index and slice of an one-dimensional array are the same as the list in Python. The index starts at 0, and the slice is left closed and right open.
Import numpy as np
Ar = np.arange (20)
# output the 4th value of ar
Print (ar [3])
# output the first four values of ar
Print (ar [: 4])
> > >
four
[0 1 2 3]
Indexing / slicing of multidimensional arrays
A two-dimensional array can be understood as two one-dimensional arrays stacked horizontally, as long as the corresponding indexes are taken respectively.
Import numpy as np
Ar = np.arange (16) .reshape (4jue 4)
# two-dimensional array indexes follow the first row and then the column (there are two ways to write it)
# Select the value of the second row and the second column
Print (ar [2] [2])
Print (ar [2jue 2])
# 2D array slicing
# take out the values of the first two rows
Print (ar [: 2])
# take out the values of the first two rows and the last two columns
Print (ar [: 2jue 2:])
> > >
[[0 1 2 3]
[4 5 6 7]
[8 9 10 11]
[12 13 14 15]]
ten
ten
[[0 1 2 3]
[4 5 6 7]]
[[2 3]
[6 7]]
The values of indexes and slices of a three-digit array are equivalent to the evolutionary version of a two-dimensional array.
Import numpy as np
Ar = np.arange (12) .reshape (3Jing 2pm 2)
Print (ar)
# 3D array index follows dimension, row and column
Print (ar [2] [0] [1])
Print (ar [2j0jue 1])
# slicing
# get the number of the first column of the first row of the first array
Print (ar [: 1 recuperating 1])
> > >
[0 1]
[2 3]]
[[4 5]
[6 7]]
[[8 9]
[10 11]
[0]
nine
nine
Boolean index and slicing
The use of Boolean arrays is the focus of this article.
# briefly show what a Boolean one-dimensional group looks like
I = np.array ([True,False,True])
J = np.array ([True,True,False,False])
Print (I)
Print (j)
> > >
[True False True]
[True True False False]
And what we often see is this:
Ar = np.arange (12) .reshape (3jue 4)
Print (ar)
Print (ar > 5)
> > >
[[0 1 2 3]
[4 5 6 7]
[8 9 10 11]]
[[False False False False]
[False False True True]
[True]]
When we need to filter out values greater than 3 in ar, we can use Boolean values to filter, as follows:
Ar = np.arange (12) .reshape (3jue 4)
Print (ar > 3)
> > >
[4 5 6 7 8 9 10 11]
Uniform distribution and normal distribution of Numpy random numbers
Generate random numbers by uniform distribution and normal distribution
# numpy.random.rand () generates a 0-1 random floating point number or N-dimensional floating point number-uniform distribution
A = np.random.rand ()
B = np.random.rand (4pd4)
Print (a)
Print (b)
> > >
0.5544023939180306
[[0.46387648 0.97345876 0.12059175 0.7565951]
[0.30192996 0.76633208 0.20107761 0.09315875]
[0.79347118 0.26714404 0.08628158 0.72510313]
[0.06606087 0.93260038 0.90268201 0.90941348]]
Generate random numbers by means of positive etheric distribution
# numpy.random.randn () generates a 0-1 random floating point number or N-dimensional floating point number-normal distribution
A = np.random.randn ()
B = np.random.randn (4pd4)
Print (a)
Print (b)
> > >
0.26901442604096687
[0.40261375-0.23541184 0.96607489-1.11253043]
[- 0.31670703 0.05841136-0.01862511 1.72597729]
[0.17052799 1.03537825-0.94375417 1.32484928]
[0.132761 0.44950533 0.44131534-0.11319535]
According to the above, I believe that everyone's understanding of. Randn () and. Rand () is not clear enough. Here is a visual way to show it:
# average distribution
# numpy.random.rand () generates a 0-1 random floating point number or N-dimensional floating point number-uniform distribution
Data1 = np.random.rand
Data2 = np.random.rand
# normal distribution
# numpy.random.randn () generates a floating point number or N-dimensional floating point number-normal distribution
Data3 = np.random.randn
Data4 = np.random.randn
Import matplotlib.pyplot as plt
% matplotlib inline
Plt.scatter (data1,data2)
Plt.scatter (data3,data4)
This is a randomly distributed pattern:
This is the pattern of normal distribution:
You can see that the imaging of normal distribution and random distribution is still quite different, of course, here is only to deepen people's understanding of .rand () and .rand (), visualization will be further learned later.
Other uses of Numpy random numbers # random integers
Print (np.random.randint (2))
# generate random integers between 2 and 10
Print ((np.random.randint (2) 10)
# generate 10 integers between 0 and 10
Print ((np.random.randint (10 heroin 10)
# generate a two-dimensional array of 10 elements between 0 and 10
Print (np.random.randint (10 refine size = (2) 5))
# generate a two-dimensional array of 10 elements between 10 and 50
Print (np.random.randint (10, 5, 5))
At this point, I believe you have a deeper understanding of "how to use Numpy's Anaconda". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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: 0
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.