Create a 1D numpy array that stores values (4, 3, 1, 33, 21, 67, 27, 89, 34, 67, 99, 89, 12, 43) AS STRING VALUES.
Hint: Explore using dtype Your code should print the following: ['4' '3' '1' '33' '21' '67' '27' '89' '34' '67' '99' '89' '12' '43']
import numpy as np
# Create the numpy array
number = np.array([4, 3, 1, 33, 21, 67, 27, 89, 34, 67, 99, 89, 12, 43])
# Print the array
print("Before adding string element: ")
print(number)
# add a string element
snum ="13"
print("\nAfter adding string element: ")
number = np.append(number , snum)
print(number)
Before adding string element:
[ 4 3 1 33 21 67 27 89 34 67 99 89 12 43]
After adding string element:
['4' '3' '1' '33' '21' '67' '27' '89' '34' '67' '99' '89' '12' '43' '13']
___________________________________________________________________
Note: If you have
queries or confusion regarding this question, please leave a
comment. I would be happy to help you. If you find it to be useful,
please upvote.
Get Answers For Free
Most questions answered within 1 hours.