Practical PRogram List 2.ipynb - Colab
Practical PRogram List 2.ipynb - Colab
ipynb - Colab
# Variation 1
# initializing lists
test_list1 = [1, 3, 4, 6, 8]
test_list2 = [4, 5, 6, 2, 10]
# Variation 2
test_list1 = [1, 3, 4, 6, 8]
test_list2 = [4, 5, 6, 2, 10]
# Variation 3
import numpy as np
# initializing lists
test_list1 = [1, 3, 4, 6, 8]
test_list2 = [4, 5, 6, 2, 10]
get_sum = sum(n_num)
https://colab.research.google.com/drive/12nDuWAlDY72rhJrBNxXqiO4cmTQxcb8I#scrollTo=bjHm50HqpeXd&printMode=true 1/6
11/1/24, 1:31 PM Practical PRogram List 2.ipynb - Colab
mean = get_sum / n
# Using Numpy
import numpy
speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]
x = numpy.mean(speed)
print(x)
if n % 2 == 0:
median1 = n_num[n//2]
median2 = n_num[n//2 - 1]
median = (median1 + median2)/2
else:
median = n_num[n//2]
print("Median is: " + str(median))
# Using Numpy
import numpy
speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]
x = numpy.median(speed)
print(x)
data = Counter(n_num)
get_mode = dict(data)
mode = [k for k, v in get_mode.items() if v == max(list(data.values()))]
if len(mode) == n:
get_mode = "No mode found"
else:
get_mode = "Mode is / are: " + ', '.join(map(str, mode))
print(get_mode)
# Using Numpy
import numpy
speed = [99,86,87,88,86,103,87,94,78,77,85,86]
x = numpy.median(speed)
print(x)
#Line Chart is used to represent a relationship between two data X and Y on a different axis.
import matplotlib.pyplot as plt
# data to display on plots
x = [2, 9]
y = [5, 10]
https://colab.research.google.com/drive/12nDuWAlDY72rhJrBNxXqiO4cmTQxcb8I#scrollTo=bjHm50HqpeXd&printMode=true 2/6
11/1/24, 1:31 PM Practical PRogram List 2.ipynb - Colab
# This will plot a simple line chart
# with elements of x as x axis and y
# as y axis
plt.plot(x, y)
plt.title("Line Chart")
Write a program to display a scatter chart for the following points (2,5), (9,10),(8,3),(5,7),(6,18).
#Scatter plots are used to observe the relationship between variables and use dots to represent the relationship between them.
import matplotlib.pyplot as plt
# data to display on plots
x = [2, 9, 8, 15, 6]
y = [5, 10, 3, 7, 18]
https://colab.research.google.com/drive/12nDuWAlDY72rhJrBNxXqiO4cmTQxcb8I#scrollTo=bjHm50HqpeXd&printMode=true 3/6
11/1/24, 1:31 PM Practical PRogram List 2.ipynb - Colab
import pandas as pd
df = pd.read_csv('/content/sample_data/mnist_train_small.csv')# file name to be given in single quotes
df.head(n=10)
6 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 ... 0.581 0.582 0.583 0.584 0.585 0.586 0.587 0.588 0.589 0.590
0 5 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
1 7 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
2 9 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
3 5 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
4 2 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
5 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
6 6 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
7 5 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
8 5 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
9 2 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
Read csv file saved in your system and display its information
import pandas as pd
df = pd.read_csv('/content/sample_data/mnist_train_small.csv')# file name to be given in single quotes
df.info()
df.describe
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 19999 entries, 0 to 19998
Columns: 785 entries, 6 to 0.590
dtypes: int64(785)
memory usage: 119.8 MB
<bound method NDFrame.describe of 6 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 ... 0.581 0.582 0.583 \
0 5 0 0 0 0 0 0 0 0 0 ... 0 0 0
1 7 0 0 0 0 0 0 0 0 0 ... 0 0 0
2 9 0 0 0 0 0 0 0 0 0 ... 0 0 0
3 5 0 0 0 0 0 0 0 0 0 ... 0 0 0
4 2 0 0 0 0 0 0 0 0 0 ... 0 0 0
... .. .. ... ... ... ... ... ... ... ... ... ... ... ...
19994 0 0 0 0 0 0 0 0 0 0 ... 0 0 0
19995 1 0 0 0 0 0 0 0 0 0 ... 0 0 0
19996 2 0 0 0 0 0 0 0 0 0 ... 0 0 0
19997 9 0 0 0 0 0 0 0 0 0 ... 0 0 0
19998 5 0 0 0 0 0 0 0 0 0 ... 0 0 0
https://colab.research.google.com/drive/12nDuWAlDY72rhJrBNxXqiO4cmTQxcb8I#scrollTo=bjHm50HqpeXd&printMode=true 4/6
11/1/24, 1:31 PM Practical PRogram List 2.ipynb - Colab
img = cv2.imread('/content/Copy of man.jpg',0) # the number zero opens the image as a grayscale image
plt.imshow(img, cmap = 'gray', interpolation = 'bicubic') #cmap specifies color mapping, gray in this case.
plt.title('man')
plt.axis('off')
plt.show()
https://colab.research.google.com/drive/12nDuWAlDY72rhJrBNxXqiO4cmTQxcb8I#scrollTo=bjHm50HqpeXd&printMode=true 5/6
11/1/24, 1:31 PM Practical PRogram List 2.ipynb - Colab
Write a program to read an image and identify its shape using Python
img = cv2.imread('/content/rgb.png',0)
print(img.shape)
(2000, 2000)
https://colab.research.google.com/drive/12nDuWAlDY72rhJrBNxXqiO4cmTQxcb8I#scrollTo=bjHm50HqpeXd&printMode=true 6/6