Write a NumPy program to replace a specific character with another in a given array of string values
- برمجة بايثون
- 2021-09-13
- mhanasmh00489829403
الأجوبة
import numpy as np
str1 = np.array([['Python-NumPy-Exercises'],
['-Python-']])
print("Original array of string values:")
print(str1)
print("\nReplace '-' with '=' character in the said array of string values:")
print(np.char.strip(np.char.replace(str1, '-', '==')))
print("\nReplace '-' with ' ' character in the said array of string values:")
print(np.char.strip(np.char.replace(str1, '-', ' ')))
Sample Output:
Original array of string values: [['Python-NumPy-Exercises'] ['-Python-']] Replace '-' with '=' character in the said array of string values: [['Python==NumPy==Exercises'] ['==Python==']] Replace '-' with ' ' character in the said array of string values: [['Python NumPy Exercises'] ['Python']]
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال