Created
September 14, 2017 20:03
-
-
Save GuidoS/0a86f54c4338f0558836fb39ad378da6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example non-working attempts to iterate through numpy array and | |
# strip all the string values | |
import numpy as np | |
a = np.array([(u' GNCU ATM', u'CK16 ', u'3a', 1), | |
(u'EMPLOYMENT SECURITY ', u' CI16', u'3b', 2)], | |
dtype=[('name', '<U254'), ('map', '<U255'), | |
('grid', '<U255'), ('OBJECTID', '<i4')]) | |
print 'original: {}\n'.format(a) | |
# # attempt 1 | |
np.char.strip(a) | |
# attempt 2 | |
for x in np.nditer(a, op_flags=['readwrite']): | |
for y in np.nditer(x, op_flags=['readwrite']): | |
y[...] = y.tostring().strip() | |
x[...] = x | |
print 'output: {}'.format(a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment