NumPy Review…Again;)

Python Review Free Exercises — #PySeries#Episode 16

J3
Jungletronics
5 min readMar 18, 2021

--

Hi, answer these twenty questions:

01#PyEx — Python —NumPy — Importing Libs:

#Import NumPy as np:

02#PyEx — Python — NumPy — Zeros:

#Create an array of 10 zeros:# output expected: 
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])

03#PyEx — Python — NumPy — Ones:

#Create an array of 10 ones:# output expected: 
array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])

04#PyEx — Python — NumPy — Ones:

#Create an array of 10 fives:# output expected: 
array([5., 5., 5., 5., 5., 5., 5., 5., 5., 5.])

05#PyEx — Python — NumPy — Integers:

#Create an array of the integers from 10 to 50:# output expected: 
array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,44, 45, 46, 47, 48, 49, 50])

06#PyEx — Python — NumPy — Arange:

#Create an array of all the even integers from 10 to 50:# output expected: 
array([10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50])

07#PyEx — Python — NumPy —Arange :

#Create a 3x3 matrix with values ranging from 0 to 8:# output expected: 
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])

08#PyEx — Python — NumPy —Identity Matrix :

#Create a 3x3 identity matrix:# output expected: 
array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]])

09#PyEx — Python — NumPy — Random Numbers:

#Use NumPy to generate a random number between 0 and 1:
#NOTE: Your result’s value should be different from the one shown #below.
# output expected:
array([0.23442116])

10#PyEx — Python — NumPy — Random Numbers:

#Use NumPy to generate an array of 25 random numbers sampled from a standard normal distribution:
#NOTE: Your result’s values should be different from the ones shown below.
# output expected:
array([-0.61659542, -0.77532828, 0.36213786, -1.28636974, 0.33286861, 0.06991562, 0.99519046, -1.12320101, -2.09591218, -0.99818646, -0.86720284, -1.13239342, -0.17099943, -0.76632253, -1.005097 , -1.73123788, -1.28889203, -1.63121734, -0.32411105, -0.30448115, -0.67660156, -1.1030128 , -1.19426878, 1.10254174, 1.30879357])

11#PyEx — Python — NumPy —Numbers generators:

#Create the following matrix:# output expected: 
array([
[0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1 ],
[0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2 ],
[0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3 ],
[0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4 ],
[0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5 ],
[0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6 ],
[0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.7 ],
[0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8 ],
[0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9 ],
[0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1. ]])

12#PyEx — Python — Numpy —Spaced Intervals :

#Create an array of 20 linearly spaced points between 0 and 1:# output expected: 
array([0. , 0.05263158, 0.10526316, 0.15789474, 0.21052632, 0.26315789, 0.31578947, 0.36842105, 0.42105263, 0.47368421, 0.52631579, 0.57894737, 0.63157895, 0.68421053, 0.73684211, 0.78947368, 0.84210526, 0.89473684, 0.94736842, 1. ])

Alright, now you will be given a starting matrix, and you will replicate the matrix outputs

IMPORTANT NOTE: Do not forget to run the cell below!

#RUN THIS CELL — THIS IS OUR STARTING MATRIX:mat = np.arange(1,26).reshape(5,5)# output expected:
array([[ 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20],
[21, 22, 23, 24, 25]])

13#PyEx — Python — NumPy — Indexing & Slicing:

#Write code that reproduces the output shown below:# output expected: 
array([[12, 13, 14, 15],
[17, 18, 19, 20],
[22, 23, 24, 25]])

14#PyEx — Python — NumPy — Indexing & Slicing:

#Write code that reproduces the output shown below:# output expected: 
20

15#PyEx — Python — NumPy —Indexing & Slicing :

#Write code that reproduces the output shown below:# output expected:
array([[ 2],
[ 7],
[12]])

16#PyEx — Python — NumPy —Indexing & Slicing :

#Write code that reproduces the output shown below:# output expected: 
array([21, 22, 23, 24, 25])

17#PyEx — Python — NumPy —Indexing & Slicing :

#Write code that reproduces the output shown below:# output expected: 
array([[16, 17, 18, 19, 20],
[21, 22, 23, 24, 25]])

18#PyEx — Python — NumPy —Stats & Math :

#Get the sum of all the values in mat:# output expected: 
325

19#PyEx — Python — NumPy —Stats & Math :

#Get the standard deviation of the values in mat:# output expected:
7.211102550927978

20#PyEx — Python — NumPy —Stats & Math :

#Get the sum of all the columns in mat:# output expected: 
array([55, 60, 65, 70, 75])

That`s it !

Get the original notebook e the notebook answer:).

See you soon!

Bye!

o/

Google Colab Notebooks are here:

Colab Questions link:)

Colab Answers link:)

Or GitHub Repo link:)

Or Files from Google Drive:)

Credits & References

INTRODUÇÃO A MACHINE LEARNING PARA CERTIFICAÇÃO HCIA-AI by crateus.ufc.br

https://www.huawei.com/en/

Posts Related:

00Episode#PySeries — Python — Jupiter Notebook Quick Start with VSCode — How to Set your Win10 Environment to use Jupiter Notebook

01Episode#PySeries — Python — Python 4 Engineers — Exercises! An overview of the Opportunities Offered by Python in Engineering!

02Episode#PySeries — Python — Geogebra Plus Linear Programming- We’ll Create a Geogebra program to help us with our linear programming

03Episode#PySeries — Python — Python 4 Engineers — More Exercises! — Another Round to Make Sure that Python is Really Amazing!

04Episode#PySeries — Python — Linear Regressions — The Basics — How to Understand Linear Regression Once and For All!

05Episode#PySeries — Python — NumPy Init & Python Review — A Crash Python Review & Initialization at NumPy lib.

06Episode#PySeries — Python — NumPy Arrays & Jupyter Notebook — Arithmetic Operations, Indexing & Slicing, and Conditional Selection w/ np arrays.

07Episode#PySeries — Python — Pandas — Intro & Series — What it is? How to use it?

08Episode#PySeries — Python — Pandas DataFrames — The primary Pandas data structure! It is a dict-like container for Series objects

09Episode#PySeries — Python — Python 4 Engineers — Even More Exercises! — More Practicing Coding Questions in Python!

10Episode#PySeries — Python — Pandas — Hierarchical Index & Cross-section — Open your Colab notebook and here are the follow-up exercises!

11Episode#PySeries — Python — Pandas — Missing Data — Let’s Continue the Python Exercises — Filling & Dropping Missing Data

12Episode#PySeries — Python — Pandas — Group By — Grouping large amounts of data and compute operations on these groups

13Episode#PySeries — Python — Pandas — Merging, Joining & Concatenations — Facilities For Easily Combining Together Series or DataFrame

14Episode#PySeries — Python — Pandas — Pandas Dataframe Examples: Column Operations

15Episode#PySeries — Python — Python 4 Engineers Keeping It In The Short-Term Memory — Test Yourself! Coding in Python, Again!

16Episode#PySeries — NumPy— NumPy Review, Again;) —Python Review Free Exercises (this one)

17Episode#PySeriesGenerators in Python — Python Review Free Hints

18Episode#PySeries — Pandas Review…Again;) — Python Review Free Exercise

19Episode#PySeriesMatlibPlot & Seaborn Python Libs — Reviewing theses Plotting & Statistics Packs

20Episode#PySeriesSeaborn Python Review — Reviewing theses Plotting & Statistics Packs

--

--

J3
Jungletronics

Hi, Guys o/ I am J3! I am just a hobby-dev, playing around with Python, Django, Ruby, Rails, Lego, Arduino, Raspy, PIC, AI… Welcome! Join us!