Reducing size of a character array in Numpy
Posted
by Morgoth
on Stack Overflow
See other posts from Stack Overflow
or by Morgoth
Published on 2010-03-23T17:39:52Z
Indexed on
2010/03/23
17:43 UTC
Read the original article
Hit count: 316
Given a character array:
In [21]: x = np.array(['a ','bb ','cccc '])
One can remove the whitespace using:
In [22]: np.char.strip(x)
Out[22]:
array(['a', 'bb', 'cccc'],
dtype='|S8')
but is there a way to also shrink the width of the column to the minimum required size, in the above case |S4
?
© Stack Overflow or respective owner