Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning SciPy for Numerical and Scientific Computing Second Edition

You're reading from   Learning SciPy for Numerical and Scientific Computing Second Edition Quick solutions to complex numerical problems in physics, applied mathematics, and science with SciPy

Arrow left icon
Product type Paperback
Published in Feb 2015
Publisher Packt
ISBN-13 9781783987702
Length 188 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Toc

Indexing and slicing arrays

There are two basic methods to access the data in a NumPy array; let's call that array for A. Both methods use the same syntax, A[obj], where obj is a Python object that performs the selection. We are already familiar with the first method of accessing a single element. The second method is the subject of this section, namely slicing. This concept is exactly what makes NumPy and SciPy so incredibly easy to manage.

The basic slice method is a Python object of the form slice(start,stop,step), or in a more compact notation, start:stop:step. Initially, the three variables, start, stop, and step are non-negative integer values, with start less than or equal to stop.

This represents the sequence of indices k = start + (i * step), where k runs from start to the largest integer k_max = start + step*int((stop-start)/step), or i from 0 to the largest integer equal to int((stop - start) / step). When a slice method is invoked on any of the dimensions of ndarray, it...

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 €18.99/month. Cancel anytime