How to Change Datatype of Elements While Iterating Through Array


In this example we will show how to change the datatype of elements while iterating through the NumPy array in Python.

Source Code

import numpy as np

n = np.array([1, 2, 3, 4, 5])

for i in np.nditer(n, flags=['buffered'], op_dtypes=['S']):
    print(i)

Output:

b'1'
b'2'
b'3'
b'4'
b'5'
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments