Page 436 - AI Ver 3.0 Class 11
P. 436
13. Create a 2D NumPy array with random values between 0 and 1, of shape (3, 4). Calculate the mean, median,
standard deviation, and sum of all elements in the array.
import numpy as np
array = np.random.rand(3, 4)
mean = np.mean(array)
median = np.median(array)
std_dev = np.std(array)
total_sum = np.sum(array)
print("Array=>",array)
print("Mean:",mean)
print("Median:",median)
print("Standard Dev:",std_dev)
print("Total Sum:",total_sum)
Output:
Array=> [[0.1323895 0.96092024 0.57495279 0.32993941]
[0.99346564 0.28274965 0.60210725 0.52907223]
[0.01546212 0.80636395 0.79479556 0.66974995]]
Mean: 0.5576640248163472
Median: 0.5885300205581695
Standard Dev: 0.3011857443905632
Total Sum: 6.6919682977961665
14. Assume two single dimension arrays. Write a Python Program to perform the four mathematical operations on
these two arrays.
import numpy as np
array1 = np.array([11,12,13,14,15])
array2 = np.array([6, 7, 8, 9, 10])
add = array1 + array2
subtract = array1 - array2
multiply = array1 * array2
divide = array1 / array2
print(add)
print(subtract)
print(multiply)
print(divide)
Output:
[17 19 21 23 25]
[5 5 5 5 5]
[66 84 104 126 150]
[1.83333333 1.71428571 1.625 1.55555556 1.5]
15. Create a dataframe with information about different types of pizzas, their sizes, prices, ingredients etc. Display the
first few rows of the dataframe.
import pandas as pd
# Create a DataFrame with information about pizzas
data = {'Pizza Name': ['Margherita', 'Pepperoni', 'BBQ Chicken', 'Veggie', 'Hawaiian'],
'Size': ['Small', 'Medium', 'Large', 'Medium', 'Small'],
'Price': [8.99, 10.99, 12.99, 9.99, 11.49],
434 Touchpad Artificial Intelligence (Ver. 3.0)-XI

