array or array-like arguments (like lists)array containing the resultsarray operators like + and *array and calculate the square root of its values, using the sqrt universal functionimport numpy as np
numbers = np.array([1, 4, 9, 16, 25, 36])
np.sqrt(numbers)
arrays with the same shape, using the add universal functionnumbers + numbers2
numbers2 = np.arange(1, 7) * 10
numbers2
np.add(numbers, numbers2)
array operatorsnp.multiply(numbers2, 5)
numbers3 = numbers2.reshape(2, 3)
numbers3
numbers4 = np.array([2, 4, 6])
np.multiply(numbers3, numbers4)
| NumPy universal functions |
|---|
Math — add, subtract, multiply, divide, remainder, exp, log, sqrt, power, and more. |
Trigonometry —sin, cos, tan, hypot, arcsin, arccos, arctan, and more. |
Bit manipulation —bitwise_and, bitwise_or, bitwise_xor, invert, left_shift and right_shift. |
Comparison —greater, greater_equal, less, less_equal, equal, not_equal, logical_and, logical_or, logical_xor, logical_not, minimum, maximum, and more. |
Floating point —floor, ceil, isinf, isnan, fabs, trunc, and more. |
©1992–2020 by Pearson Education, Inc. All Rights Reserved. This content is based on Chapter 5 of the book Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and the Cloud.
DISCLAIMER: The authors and publisher of this book have used their best efforts in preparing the book. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The authors and publisher make no warranty of any kind, expressed or implied, with regard to these programs or to the documentation contained in these books. The authors and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs.