Codes:
import numpy as np
# Create a 2x2 array with random values
array_2d = np.random.rand(2, 2)
# Calculate the mean of each row
row_means = np.mean(array_2d, axis=1)
# Subtract the mean of each row from each element
result_array = array_2d - row_means[:, np.newaxis]
print("2x2 Array with Random Values:")
print(array_2d)
print("\nResult Array after Subtracting Row Means:")
print(result_array)
0 Comments