python - Longest string in numpy object_ array -
I am using a numpy object_ array to store the variable length string, e.g.
a = Np.array (['hello', 'world', '!'], Dtype = np.object_)
An easy way to find the length of the long string without looping array on all elements?
maximum (A, key = lane)
gives len (max (a, key = len))
gives you its length without you need a clear loop code, but surely max
internally Will do its own looping because it probably can not identify the "longest string" in any other way.
Comments
Post a Comment