Practice Numpy
Numpy is one of the basic and most used packages in Python. It is mostly used for scientific computing.
Most important Data Type in Numpy is Array.
import numpy as np
And you have installed the numpy package in your system. Now, check the important and basic functions present in Numpy package to play around your dataset.
1. Import numpy
import numpy as n
2. Create an array in python
arr = np.array([0,1,2,3,45,6])
print(arr)
[ 0 1 2 3 45 6]
3. Create a two dimensional array
arr2 = np.array([[1,2,3],[5,6,7]])
print(arr2.shape)
(2, 3)
4. Create an array of all ones of 3 rows and 4 columns
one = np.ones((3,4))
print(one)
[[1. 1. 1. 1.] [1. 1. 1. 1.] [1. 1. 1. 1.]]
5. Create an array with all zeros in 3 rows and and 4 columns
zero = np.zeros((3,4)) print(zero) [[0. 0. 0. 0.] [0. 0. 0. 0.] [0. 0. 0. 0.]]
6. Create an array with random values for 3 rows and 4 columns
rand = np.random.random((3,4))
print(rand)
[[0.15340682 0.57965139 0.15538918 0.35086011] [0.35453516 0.96230823 0.49873964 0.022157 ] [0.35144323 0.42548206 0.96434164 0.67721939]]
7. Statistical functions available in Numpy
a. Min
b. Max
c. Mean
d. Median
e. Standard Deviation
First of all, we will be creating a series of random numbers using np.random.normal function which gives you the flexibility to choose the range in which you want to have your random numbers, irony is that you can restrict the randomness of your random number 😛
import numpy as np stat = np.random.normal(8,1.5,10) print(stat) [8.84371443 7.7014931 6.72789277 5.73700496 8.46005265 9.08922936 8.71789028 6.84561345 8.20465228 7.26850749]
There are three parameters in the function separated by a comma.
8 is the base value
1.5 is the range you which you are providing to the function i.e. the values will vary in the range 6.5 to 9.5
10 is the number of random values
8. Now let’s get the min, max, mean, standard deviation from “stat”
print(min(stat))
5.737004956818833
print(max(stat))
9.089229356076414
print(np.mean(stat))
7.759605075083963
print(np.std(stat))
1.0385313768435045
9. Matrix multiplication in numpy
x = [[1,2],[4,5]] y = [[6,7],[8,9]] z = np.matmul(x,y) print(z) [[22 25] [64 73]]
The Data Monk services
We are well known for our interview books and have 70+ e-book across Amazon and The Data Monk e-shop page . Following are best-seller combo packs and services that we are providing as of now
- YouTube channel covering all the interview-related important topics in SQL, Python, MS Excel, Machine Learning Algorithm, Statistics, and Direct Interview Questions
Link – The Data Monk Youtube Channel - Website – ~2000 completed solved Interview questions in SQL, Python, ML, and Case Study
Link – The Data Monk website - E-book shop – We have 70+ e-books available on our website and 3 bundles covering 2000+ solved interview questions. Do check it out
Link – The Data E-shop Page - Instagram Page – It covers only Most asked Questions and concepts (100+ posts). We have 100+ most asked interview topics explained in simple terms
Link – The Data Monk Instagram page - Mock Interviews/Career Guidance/Mentorship/Resume Making
Book a slot on Top Mate
The Data Monk e-books
We know that each domain requires a different type of preparation, so we have divided our books in the same way:
1. 2200 Interview Questions to become Full Stack Analytics Professional – 2200 Most Asked Interview Questions
2.Data Scientist and Machine Learning Engineer -> 23 e-books covering all the ML Algorithms Interview Questions
3. 30 Days Analytics Course – Most Asked Interview Questions from 30 crucial topics
You can check out all the other e-books on our e-shop page – Do not miss it
For any information related to courses or e-books, please send an email to [email protected]