arrays and Individual Numeric Values¶array Operators¶array operators perform operations on entire arrays. arrays and scalar numeric values, and between arrays of the same shape.import numpy as np
numbers = np.arange(1, 6)
numbers
numbers * 2
numbers ** 3
numbers # numbers is unchanged by the arithmetic operators
numbers += 10
numbers
arrays of the same size and shape. numbers * 2 is equivalent to numbers * [2, 2, 2, 2, 2] for a 5-element array.arrays of different sizes and shapes, enabling some concise and powerful manipulations.arrays¶arrays of the same shapenumbers2 = np.linspace(1.1, 5.5, 5)
numbers2
numbers * numbers2
arrays¶arrays with individual values and with other arraysarrays of Boolean values in which each element’s True or False value indicates the comparison resultnumbers
numbers >= 13
numbers2
numbers2 < numbers
numbers == numbers2
numbers == numbers
©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.