Reader small image

You're reading from  Learning IPython for Interactive Computing and Data Visualization, Second Edition

Product typeBook
Published inOct 2015
Reading LevelBeginner
Publisher
ISBN-139781783986989
Edition1st Edition
Languages
Right arrow
Author (1)
Cyrille Rossant
Cyrille Rossant
author image
Cyrille Rossant

Cyrille Rossant, PhD, is a neuroscience researcher and software engineer at University College London. He is a graduate of École Normale Supérieure, Paris, where he studied mathematics and computer science. He has also worked at Princeton University and Collège de France. While working on data science and software engineering projects, he gained experience in numerical computing, parallel computing, and high-performance data visualization. He is the author of Learning IPython for Interactive Computing and Data Visualization, Second Edition, Packt Publishing.
Read more about Cyrille Rossant

Right arrow

Creating and loading arrays


In this section, we will see how to create and load NumPy arrays.

Creating arrays

First, there are several NumPy functions for creating common types of arrays. For example, np.zeros(shape) creates an array containing only zeros. The shape argument is a tuple giving the size of every axis. Hence, np.zeros((3, 4)) creates an array of size (3, 4) (note the double parentheses, because we pass a tuple to the function).

Here are some further examples:

In [1]: import numpy as np
        print("ones", np.ones(5))
        print("arange", np.arange(5))
        print("linspace", np.linspace(0., 1., 5))
        print("random", np.random.uniform(size=3))
        print("custom", np.array([2, 3, 5]))
Out[1]: ones [ 1.  1.  1.  1.  1.]
        arange [0 1 2 3 4]
        linspace [ 0.    0.25  0.5   0.75  1.  ]
        random [ 0.68361911  0.33585308  0.70733934]
        custom [2 3 5]

The np.arange() and np.linspace() functions create arrays with regularly spaced numbers. The np...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learning IPython for Interactive Computing and Data Visualization, Second Edition
Published in: Oct 2015Publisher: ISBN-13: 9781783986989

Author (1)

author image
Cyrille Rossant

Cyrille Rossant, PhD, is a neuroscience researcher and software engineer at University College London. He is a graduate of École Normale Supérieure, Paris, where he studied mathematics and computer science. He has also worked at Princeton University and Collège de France. While working on data science and software engineering projects, he gained experience in numerical computing, parallel computing, and high-performance data visualization. He is the author of Learning IPython for Interactive Computing and Data Visualization, Second Edition, Packt Publishing.
Read more about Cyrille Rossant