NEP -DAA -DESIGN AND ANALYSIS OF ALOGRITHM

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8 PROGRAM 9 PROGRAM 10 PROGRAM 11 PROGRAM 12

PART B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 PROGRAM B7 PROGRAM B8 . . .

7. Create array using NumPy and perform array operations

 
 7. Create array using NumPy and perform array operations

import numpy as np

# Create a NumPy array
arr = np.array([1, 2, 3, 4, 5])

# Print the array
print("Original array:")
print(arr)

# Perform array operations

# Adding a constant to the array
arr_plus_const = arr + 10
print("\nArray after adding a constant:")
print(arr_plus_const)

# Subtracting a constant from the array
arr_minus_const = arr - 3
print("\nArray after subtracting a constant:")
print(arr_minus_const)

# Multiplying the array by a constant
arr_times_const = arr * 2
print("\nArray after multiplying by a constant:")
print(arr_times_const)

# Dividing the array by a constant
arr_div_const = arr / 2
print("\nArray after dividing by a constant:")
print(arr_div_const)

# Element-wise operations between two arrays
arr2 = np.array([5, 4, 3, 2, 1])

# Adding two arrays element-wise
arr_sum = arr + arr2
print("\nArray after element-wise addition:")
print(arr_sum)

# Subtracting two arrays element-wise
arr_diff = arr - arr2
print("\nArray after element-wise subtraction:")
print(arr_diff)

# Multiplying two arrays element-wise
arr_prod = arr * arr2
print("\nArray after element-wise multiplication:")
print(arr_prod)

# Dividing two arrays element-wise
arr_div = arr / arr2
print("\nArray after element-wise division:")
print(arr_div)

# Dot product of two arrays
dot_product = np.dot(arr, arr2)
print("\nDot product of the two arrays:")
print(dot_product)

# Sum, mean, maximum, and minimum of the array
print("\nSum of the array:", np.sum(arr))
print("Mean of the array:", np.mean(arr))
print("Maximum value in the array:", np.max(arr))
print("Minimum value in the array:", np.min(arr))