Page 256 - Robotics and AI class 10
P. 256
e. (i) Python code for joining the contents of two NumPy arrays
import numpy as np
# Creating two example arrays
array1 = np.array([1, 2, 3])
array2 = np.array([4, 5, 6])
# Joining arrays along axis 0 (row-wise concatenation)
joined_array = np.concatenate((array1, array2))
print("Joined Array:")
print(joined_array)’
Output:
Joined Array:[1 2 3 4 5 6]
(ii) Python code for splitting the contents of two NumPy arrays.
import numpy as np
original_array = np.array([1, 2, 3, 4, 5, 6]) # Creating an example array
split_arrays = np.split(original_array, 2) # Splits into two equal-sized array
print("Split Arrays:")
for sub_array in split_arrays:
print(sub_array)
Output:
Split Arrays:
[1 2 3]
[4 5 6]
f. (i) Python code for searching a numpy array.
import numpy as np
# Creating a numpy array
arr = np.array([10, 20, 30, 40, 50])
# Searching for a specific value (e.g., 30)
value_to_find = 30
index = np.where(arr == value_to_find)
if index[0].size > 0:
print(f"{value_to_find} found at index:", index[0][0])
else:
print(f"{value_to_find} not found in the array.")
Output:
30 found at index: 2
(ii) Python code for sorting a Numpy Array.
import numpy as np
254 Touchpad Robotics & Artificial Intelligence-X

