Numpy

Array operations with NumPy

Python
# Demonstrating basic array operations with NumPy

import numpy as np

# Creating two arrays for demonstration
array1 = np.array([1, 2, 3, 4, 5, 6])
array2 = np.array([6, 5, 4, 3, 2, 1])

# Element-wise addition
addition_result = np.add(array1, array2)
print("Addition Result:", addition_result)

# Element-wise multiplication
multiplication_result = np.multiply(array1, array2)
print("Multiplication Result:", multiplication_result)

# Dot product of both arrays
dot_product_result = np.dot(array1, array2)
print("Dot Product Result:", dot_product_result)

# Reshaping array1 to a 2x3 matrix
reshaped_array = np.reshape(array1, (2, -1))
print("Reshaped Array (2x3):\\n", reshaped_array)

# Computing the mean of array1
mean_array1 = np.mean(array1)
print("Mean of Array1:", mean_array1)

# Finding the maximum value in array2
max_array2 = np.max(array2)
print("Maximum Value in Array2:", max_array2)