checking S versus U dtype
![](https://secure.gravatar.com/avatar/ad13088a623822caf74e635a68a55eae.jpg?s=120&d=mm&r=g)
A = np.asarray([[1, 0, 0],['E', 1, 0],['E', 'E', 1]], dtype='<U1') A array([['1', '0', '0'], ['E', '1', '0'], ['E', 'E', '1']], dtype='<U1') A.dtype
What's the best way to check whether a numpy array is string or bytes on python3? using char? dtype('<U1')
A.dtype.char 'U' A.dtype.char == 'U' True A.dtype.char == 'S' False A.astype('<S1').dtype.char == 'S' True A.astype('<S1').dtype.char == 'U' False
background: I don't know why sometimes I got S and sometimes U on Python 3.4, and I want the code to work with both
A == 'E' array([[False, False, False], [ True, False, False], [ True, True, False]], dtype=bool)
A.astype('<S1') == 'E' False A.astype('<S1') == b'E' array([[False, False, False], [ True, False, False], [ True, True, False]], dtype=bool)
Josef
participants (1)
-
josef.pktd@gmail.com