import numpy as np
from scipy import stats # for mode()
# e) Join and split Numpy arrays
# a) Getting elements from Numpy arrays print("e) Join and Split Arrays")
using index values arr1 = [Link]([1, 2, 3])
print("a) Getting elements using index arr2 = [Link]([4, 5, 6])
values") joined = [Link]((arr1, arr2))
arr = [Link]([10, 20, 30, 40, 50]) print("Joined Array:", joined)
print("Array:", arr) split_arr = np.array_split(joined, 3)
print("First element:", arr[0]) print("Split Arrays:", split_arr)
print("Third element:", arr[2]) print()
print("Last element:", arr[-1])
print() # f) Searching and sorting of Numpy
arrays
# b) Numpy array slicing print("f) Searching and Sorting")
print("b) Array Slicing") nums = [Link]([15, 42, 7, 23, 7, 9])
print("Elements from index 1 to 3:", print("Array:", nums)
arr[1:4]) indices = [Link](nums == 7)
print("Every alternate element:", arr[::2]) print("Positions where 7 occurs:", indices)
print() sorted_nums = [Link](nums)
print("Sorted Array:", sorted_nums)
# c) Getting Numpy array shape and print()
reshaping them
print("c) Shape and Reshape") # g) Using mean, median and mode
arr2 = [Link]([[1, 2, 3], [4, 5, 6]]) methods
print("Original 2D Array:\n", arr2) print("g) Mean, Median and Mode")
print("Shape of array:", [Link]) data = [Link]([10, 20, 20, 30, 40])
reshaped = [Link](3, 2) print("Data:", data)
print("Reshaped Array (3x2):\n", print("Mean:", [Link](data))
reshaped) print("Median:", [Link](data))
print() print("Mode:", [Link](data,
keepdims=True).mode[0])
# d) Iterating a Numpy array
print("d) Iterating through elements")
for x in [Link](arr2):
print(x, end=' ')
print("\n")
Write a Python program to calculate the electricity bill. Accept the last meter reading
and current meter reading and the rate per unit from the user.
Calculate the number of units and total bill consumption for the user.
17. A company decided to give bonus of 5% to an employee if his/her year of service is
more than 5 years. Write a Python program to ask the user for their salary and year of
service and print the net bonus amount.