Unit 25Demystifying Universal Functions

Vectorized universal functions, or ufuncs, are a functional counterpart of broadcasting. You can apply ufuncs to all array items at once in one function call. numpy provides a lot of ufuncs, and here are some of them:

  • arithmetic: add, multiply, negative, exp, log, sqrt

  • trigonometric: sin, cos, hypot

  • bitwise: bitwise_and, left_shift

  • relational and logical: less, logical_not, equal

  • maximum and minimum

  • functions for working with floating-point numbers: isinf, isfinite, floor, isnan

Let’s say we recorded the stock prices for the eight sap symbols after and before the weekend of 01/10/2016 in a one-dimensional array called stocks:

 stocks
=> array([ 140.49, 0.97, 40.68, 41.53, 55.7 , 57.21, 98.2 ,

Get Data Science Essentials in Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.