Lesson 5 ❮ Lesson List ❮ Top Page
❯ 5.3 Universal Function
5.4 Join, Split, and Transpose
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
EXPECTED COMPLETION TIME
❲▹❳ Video 7m 4s
☷ Interactive readings 5m
✑ Practice 5.3 (G Colab) 25m
Universal functions (or ufunc) are NumPy functions that operate on the ndarray object. Many ufunc are related to mathematical operations between arrays.
Math operations such as
add()
subtract()
multiply()
divide()
power()
can be easily applied.
amin(ar), amax(ar)
return the minimum, maximum of an array.
sum(ar)
compute the sum of all elements.
mean(ar)
compute the arithmetic mean.
median(ar)
compute the median.
std(ar)
compute the standard deviation.
quantile(ar,q)
computes the q-th quantile of the data.
For 2-D array, you can add an extra argument:
axis=0 to compute the rows statistics
axis=1 to compute the columns statistics
e, pi
return the value of Euler's constant and pi.
sin(), cos() and tan()
take values in radians and produce the corresponding sin, cos and tan values.
sinh(), cosh() and tanh()
take values in radians and produce the corresponding sinh, cosh and tanh values.
log(), log10()
function to perform corresponding log at the base e and 10.
unique()
return the unique elements from any array, e.g., create a set array. (should only be 1-D)
union1d(ar1, ar2)
find the union of ar1 and ar2.
intersect1d(ar1, ar2)
find the intersection of ar1 and ar2.
setdiff1d(ar1, ar2)
find the set difference of ar1 and ar2.
isin(ar1, ar2)
test whether each element of ar1 is also present in ar2.
(Note that Python set cannot be converted to ndarray)