SHARE
TWEET

Untitled




Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- t = np.array([['one','two','three'],['four','five','six']], dtype=object)
- np.min(t)
- # gives 'five'
- np.max(t)
- # gives 'two'
- # Vectorize takes a Python function and converts it into a Numpy
- # vector function that operates on arrays
- np_len = np.vectorize(lambda x: len(x))
- np_len(t)
- # gives array([[3, 3, 5], [4, 4, 3]])
- idx = np_len(t).argmin(0) # get the index along the 0th axis
- # gives array([0, 0, 1])
- result = t
- for i in idx[1:]:
- result = result[i]
- print result
- # gives "two", the string with the smallest length
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.