Q:

Write a NumPy program to concatenate element-wise two arrays of string

0

Write a NumPy program to concatenate element-wise two arrays of string

All Answers

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

import numpy as np
x1 = np.array(['Python', 'PHP'], dtype=np.str)
x2 = np.array([' Java', ' C++'], dtype=np.str)
print("Array1:")
print(x1)
print("Array2:")
print(x2)
new_array = np.char.add(x1, x2)
print("new array:")
print(new_array)

Sample Input:

(['Python', 'PHP'], dtype=np.str)
([' Java', ' C++'], dtype=np.str)

Sample Output:

Array1:
['Python' 'PHP']
Array2:
[' Java' ' C++']
new array:
['Python Java' 'PHP C++']

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