0
import numpy as np

arr1 = np.array([1, 2, 3, 4, 5, 6, 7])
arr2 = np.array(['n', 'b', 'c', 'y', 'f', 'j', 'p'])

l = np.stack((arr1, arr2), axis=1)
print(l)

the output is:

enter image description here

i would like that the types will be like the input so that the output will be:

enter image description here

1 Answers1

0

Numpy tries to generalize to a single type for each array. It gets more tricky if you want sections of the array to be a different python type than others. If you really want to preserve the dtype of the arrays, then there are a number of other threads that address this:

Store different datatypes in one NumPy array?

numpy: is it possible to preserve the dtype of columns when using column_stack