Is there any builtin operation in NumPy that returns the length of each string in an array?
I don't think any of the NumPy string operations does that, is this correct?
I can do it with a for
loop, but maybe there's something more efficient?
import numpy as np
arr = np.array(['Hello', 'foo', 'and', 'whatsoever'], dtype='S256')
sizes = []
for i in arr:
sizes.append(len(i))
print(sizes)
[5, 3, 3, 10]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…