I am trying to create an array of zeros and three-column types (integer, float, character). Reference question
Doubt
Why dtype=S here is creating a binary String?
arr = np.zeros((3,), dtype=('i4,f4,S'))
arr
>>array([[(0, 0., b''), (0, 0., b''), (0, 0., b'')]],
dtype=[('f0', '<i4'), ('f1', '<f4'), ('f2', 'S')])
Issue
Assignment of characters is not working, instead results in blank strings b''.
arr[:] = [(1, 2., 'A'),
(2, 2., 'B'),
(3, 3., 'C')]
arr
>>array([[(1, 2., b''), (2, 2., b''), (3, 3., b'')]],
dtype=[('f0', '<i4'), ('f1', '<f4'), ('f2', 'S')])
Doubt
Why is problem solved by using dtype='O', or dtype='a40' a python object?
x = np.zeros((3,), dtype=('i4,f4,O')) # same result goes with dtype='a40'
new_data = [(1, 2., "A"), (2, 2., "B"), (3, 3., "C")]
x[:] = new_data
print(x)
>>[(1, 2., 'A') (2, 2., 'B') (3, 3., 'C')]
How a40 is different from S, O and U dtypes for NumPy string elements?