Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
NumPy Essentials

You're reading from  NumPy Essentials

Product type Book
Published in Apr 2016
Publisher
ISBN-13 9781784393670
Pages 156 pages
Edition 1st Edition
Languages
Authors (3):
Leo (Liang-Huan) Chin Leo (Liang-Huan) Chin
Profile icon Leo (Liang-Huan) Chin
Tanmay Dutta Tanmay Dutta
Profile icon Tanmay Dutta
Shane Holloway Shane Holloway
Profile icon Shane Holloway
View More author details

Table of Contents (16) Chapters

NumPy Essentials
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1. An Introduction to NumPy 2. The NumPy ndarray Object 3. Using NumPy Arrays 4. NumPy Core and Libs Submodules 5. Linear Algebra in NumPy 6. Fourier Analysis in NumPy 7. Building and Distributing NumPy Code 8. Speeding Up NumPy with Cython 9. Introduction to the NumPy C-API 10. Further Reading

Creating arrays


Arrays can be created in a number of ways, for instance from other data structures, by reading files on disk, or from the Web. For the purposes of this chapter, whose aim is to familiarize us with the core characteristics of a NumPy array, we will be creating arrays using lists or various NumPy functions.

Creating arrays from lists

The simplest way to create an array is using the array function. To create a valid array object, arguments to array functions need to adhere to at least one of the following conditions:

  • It has to be a valid iterable value or sequence, which may be nested
  • It must have an __array__ method that returns a valid numpy array

Consider the following snippet:

In [32]: x = np.array([1, 2, 3]) 
 
In [33]: y = np.array(['hello', 'world']) 

The first condition is always true for Python lists and tuples. When creating an array from lists or tuples, the input may consist of different (heterogeneous) data types. The array function, however, will normally...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}