## Key Concepts

Review core concepts you need to learn to master this subject

NumPy Arrays

Creating NumPy Arrays from files

NumPy element-wise arithmetic operations

Accessing NumPy Array elements by index

Indexing NumPy elements using conditionals

NumPy element-wise logical operations

NumPy Arrays

NumPy Arrays

*NumPy* (short for “Numerical Python”) is a Python module used for numerical computing, creating arrays and matrices, and performing very fast operations on those data structures. The core of NumPy is a multidimensional Array object.

The NumPy `.array()`

method is used to create new NumPy Arrays.

Creating NumPy Arrays from files

Creating NumPy Arrays from files

NumPy Arrays can be created from data in CSV files or other delimited text by using the `np.genfromtxt()`

method.

The named parameter `delimiter`

is used to determine the delimiting character between values.

NumPy element-wise arithmetic operations

NumPy element-wise arithmetic operations

NumPy Arrays support element-wise operations, meaning that arithmetic operations on arrays are applied to each value in the array.

Multiple arrays can also be used in arithmetic operations, provided that they have the same lengths.

Accessing NumPy Array elements by index

Accessing NumPy Array elements by index

Individual NumPy Array elements can be accessed by index, using syntax identical to Python lists: `array[index]`

for a single element, or `array[start:end]`

for a slice, where `start`

and `end`

are the starting and ending indexes for the slice.

Nested Arrays or elements can be accessed by adding additional comma-separated parameters.

Indexing NumPy elements using conditionals

Indexing NumPy elements using conditionals

NumPy elements can be indexed using conditionals. The syntax to filter an array using a conditional is `array_name[conditional]`

.

The returned array will contain only the elements for which the conditional evaluates to `True`

.

NumPy element-wise logical operations

NumPy element-wise logical operations

NumPy Arrays support element-wise logical operations, returning new Arrays populated with `False`

or `True`

based on their evaluation.

- 1Sarah records her second-grade class’s grades in an online spreadsheet. Her web browser records that she visited that spreadsheet, in addition to every other site she’s visited. Those sites record…
- 2To use NumPy with Python, import it at the top of your file using the following line: import numpy as np Writing as np allows us to use np as a shorthand for NumPy, which saves us time when cal…
- 3NumPy includes a powerful data structure known as an
*array*. A NumPy array is a special type of list. It’s a data structure that organizes multiple items. Each item can be of any type (strings, … - 4Typically, you won’t be entering data directly into an array. Instead, you’ll be importing the data from somewhere else. We’re able to transform CSV (comma-separated values) files into arrays usin…
- 5Generally, NumPy arrays are more efficient than lists. One reason is that they allow you to do
*element-wise operations*. An element-wise operation allows you to quickly perform an operation, such … - 6Arrays can also be added to or subtracted from each other in NumPy, assuming the arrays have the same number of elements. When adding or subtracting arrays in NumPy, each element will be added/sub…
- 7In Python, we can create lists that are made up of other lists. Similarly, in NumPy we can create an array of arrays. If the arrays that make up our bigger array are all the same size, then it has …
- 8NumPy allows us to select elements from an array using their indices. Consider the one-dimensional array a = np.array([5, 2, 7, 0, 11]) If we wanted to select the first element in this array, we…
- 9Selecting elements from a 2-d array is very similar to selecting them from a 1-d array, we just have two indices to select from. The syntax for selecting from a 2-d array is a[row,column] where a i…
- 10Another useful thing that arrays can do is perform element-wise
*logical operations*. For instance, suppose we want to know how many elements in an array are greater than 5. We can easily write som… - 11Let’s take a second and review. In this lesson, you learned the basics of the NumPy package. Here are some key points: - Arrays are a special type of list that allows us to store values in an orga…

## What you'll create

Portfolio projects that showcase your new skills

## How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory