For some reason I'm struggling to initialize a numpy.chararray with spaces.
This works:
char_array1 = np.chararray((3, 3))
char_array1[:] = 'a'
char_array1
Output:
chararray([['a', 'a', 'a'],
['a', 'a', 'a'],
['a', 'a', 'a']],
dtype='|S1')
This doesn't:
char_array2 = np.chararray((3, 3))
char_array2[:] = ' '
char_array2
Output:
chararray([['', '', ''],
['', '', ''],
['', '', '']],
dtype='|S1')
What is causing this? I can't see an option to strip the items or something.
help(chararray): Thechararrayclass exists for backwards compatibility with Numarray, it is not recommended for new development. Starting from numpy1.4, if one needs arrays of strings, it is recommended to use arrays ofdtypeobject_,string_orunicode_, and use the free function in thenumpy.charmodule for fast vectorized string operations.