Professional Documents
Culture Documents
I037 - Manas Patel Experiment08
I037 - Manas Patel Experiment08
I037 - Manas Patel Experiment08
PRACTICAL 8
4. Write a NumPy program to convert the values of Centigrade degrees into Fahrenheit
degrees and vice versa. Values are stored into a NumPy array.
PRACTICAL 8
b. Describe with example problems how axis 0 and axis 1 are used in numpy.
Ans. In numpy axis 0 refers to horizontal axis or rows and axis 1 refers to vertical axis or
columns. While performing action, if axis is 0 then action is performed on rows that satisfy the
condition. When axis is 1 then action will be performed on columns that satisfy the conditions.
1 | Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
For example
Let data frame (df) be
team points assists Rebound
0 A 25 5 11
1 A 12 7 8
2 B 15 8 10
3 B 14 5 9
For Axis=0
Code:
df.mean(axis=0)
Output:
0 13.666
1 9.0000
2 11.000
3 9.3333
dtype: float64
For Axis=1
Code:
df.mean(axis=1)
Output:
Points 16.5
Assists 6.25
Rebound 9.50
dtype: float64
2 | Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
3 | Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
a. An identity matrix
b. A symmetric matrix with only 1s and 0s
c. A diagonal matrix
d. A null matrix
5. import numpy as np
a= np.array([7,10,2,4,13,16])
test=np.percentile(a,50)
print(test)
c. 8.5
a. 11.5
b. 10
c. 8.5
d. 7
#1-D
arr1=np.zeros(5)
print('Array 1:',arr1)
#2-D
arr2=np.ones((4,3),dtype=int)
print('Array 2:',arr2)
4 | Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
print('<-------------------------------------------------->')
print('<-------------------------------------------------->')
print('<-------------------------------------------------->')
OUTPUT:
5 | Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
Q.2
CODE:
#create 5x6 array between 10 and 370 with difference between element are 12 and even
number in even row and odd column
import numpy as np
arr=np.arange(10,370,12)
arr=arr.reshape(5,6)
print('Array:\n',arr)
6 | Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
OUTPUT:
Q.3
CODE:
#Create 8 by 8 with given pattern
import numpy as np
x=np.zeros((8,8),dtype=int)
7 | Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
print('All Zeros:\n',x)
x[::2,1::2]=1
print('Pattern Even Row and Odd Coumns:\n',x)
x[1::2,::2]=2
print('Pattern Odd Row and Even Coumns:\n',x)
OUTPUT:
Q.4
CODE:
#convert celcius to farenheit in numpy
import numpy as np
values=[25,34,35.5,23.4]
8 | Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
c=np.array(values)
print('Celcius:',c)
f=np.round((9*c/5+32),2)
print('farenheit:',f)
OUTPUT:
3. Conclusion (Learning Outcomes): The learning gains from the practical was to learn
about library NumPy which is used to create matrices and array and manipulating it to
make patterns or to make table like structure using arrays data.
• Windows + R
• Cmd
• Cd c:\Users\mpstme.student\AppData\Local\Programs\Python\Python310
• Python.exe -m pip install --upgrade pip
• Cd scripts
• Pip install numpy
• Pip install pandas
• Pip install matplotlib
9 | Page