Q:

Write a NumPy program to combine last element with first element of two given ndarray with different shapes

0

Write a NumPy program to combine last element with first element of two given ndarray with different shapes

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
array1 = ['PHP','JS','C++']
array2 = ['Python','C#', 'NumPy']    
print("Original arrays:")          
print(array1)
print(array2)          
result  = np.r_[array1[:-1], [array1[-1]+array2[0]], array2[1:]]   
print("\nAfter Combining:")       
print(result)

Sample Output:

Original arrays:
['PHP', 'JS', 'C++']
['Python', 'C#', 'NumPy']

After Combining:
['PHP' 'JS' 'C++Python' 'C#' 'NumPy']

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now