Skip to Content
Mastering Numerical Computing with NumPy
book

Mastering Numerical Computing with NumPy

by Umit Mert Cakmak, Tiago Antao, Mert Cuhadaroglu
June 2018
Intermediate to advanced
248 pages
5h 27m
English
Packt Publishing
Content preview from Mastering Numerical Computing with NumPy

NumPy array operations

This section will guide you through the creation and manipulation of numerical data with NumPy. Let's start by creating a NumPy array from the list:

In [17]: my_list = [2, 14, 6, 8]         my_array = np.asarray(my_list)         type(my_array)Out[17]: numpy.ndarray

Let's do some addition, subtraction, multiplication, and division with scalar values:

In [18]: my_array + 2Out[18]: array([ 4, 16, 8, 10])In [19]: my_array - 1Out[19]: array([ 1, 13, 5, 7])In [20]: my_array * 2Out[20]: array([ 4, 28, 12, 16, 8])In [21]: my_array / 2Out[21]: array([ 1. , 7. , 3. , 4. ])

It's much harder to do the same operations in a list because the list does not support vectorized operations and you need to iterate its elements. There are many ways to create ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Numerical Computing with Python

Numerical Computing with Python

Pratap Dangeti, Allen Yu, Claire Chung, Aldrin Yim
Scientific Computing with Python - Second Edition

Scientific Computing with Python - Second Edition

Claus Führer, Claus Fuhrer, Jan Erik Solem, Olivier Verdier
SciPy and NumPy

SciPy and NumPy

Eli Bressert

Publisher Resources

ISBN: 9781788993357Supplemental Content