Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Numpy: Vectorize len

  • vectorize
  • len
import numpy as np

animals = np.array(['Cow', 'Elephant', 'Snake', 'Camel', 'Praying Mantis'])
print(animals)

vlen = np.vectorize(len)
print(vlen(animals))
['Cow' 'Elephant' 'Snake' 'Camel' 'Praying Mantis']
[ 3  8  5  5 14]