I would like to create a numpy array with mixed types. The other SO questions that I found either create an object based array or an nested array.
Both I do not want.
How would the syntax look like to have a numpy array with one str and two int columns?
This is my present code:
import numpy as np
b = np.empty((0, 3), )
b = np.insert(b, b.shape[0], [[1, 2, 3]], axis=0)
b = np.insert(b, b.shape[0], [[1, 2, 3]], axis=0)
print(b)
print("---")
a = np.empty((0, 3), dtype='S4, int, int')
a = np.insert(a, a.shape[0], ("a", 2, 3), axis=0)
a = np.insert(a, a.shape[0], ("a", 2, 3), axis=0)
print(a)
The output:
[[1. 2. 3.]
[1. 2. 3.]]
---
[[(b'a', 2, 3) (b'a', 2, 3) (b'a', 2, 3)]
[(b'a', 2, 3) (b'a', 2, 3) (b'a', 2, 3)]]
EDIT:
And what I need for the array a is:
[["a" 2 3]
["a" 2 3]]
pandasnp.array([('a', 1, 2), ('b', 2, 3)], dtype=np.dtype('S4, int, int'))