I'm using a numpy object_ array to store variable length strings, e.g.
a = np.array(['hello','world','!'],dtype=np.object_)
Is there an easy way to find the length of the longest string in the array without looping over all elements?
|
|
|||||
|
If you store the string in a numpy array of dtype object, then you can't get at the size of the objects (strings) without looping. However, if you let np.array decide the dtype, then you can find out the length of the longest string by peeking at the dtype:
|
|||
|
No as the only place the length of each string is known is by the string. So you have to find out from every string what its length is. |
|||
|
Say I want to get the longest string in the second column:
|
|||
|