How to Create a NumPy Array with Data Type String


In this example we will show how to create a NumPy array with data type string in Python.

Source Code

import numpy as np

n = np.array([1, 2, 3, 4, 5, 6], dtype='S')

print(n)
print(n.dtype)

Output:

[b'1' b'2' b'3' b'4' b'5' b'6']
|S1
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments