Podcast
Questions and Answers
What will be the output when slicing the array from index 1 to index 5?
What will be the output when slicing the array from index 1 to index 5?
- [2 3 4 5] (correct)
- [3 4 5 6]
- [1 2 3 4]
- [4 5 6 7]
If an array is sliced from index 4 to the end, which part of the array will be returned?
If an array is sliced from index 4 to the end, which part of the array will be returned?
- [4 5 6 7]
- [1 2 3 4]
- [6 7]
- [5 6 7] (correct)
When creating a DataFrame from two Series, what structure does the resultant DataFrame take?
When creating a DataFrame from two Series, what structure does the resultant DataFrame take?
- A single column
- A two-dimensional array
- A single-dimensional array
- A multi-dimensional table (correct)
How would you obtain every other element from index 1 to index 5 in a NumPy array?
How would you obtain every other element from index 1 to index 5 in a NumPy array?
What is the term for a single column in a Pandas DataFrame?
What is the term for a single column in a Pandas DataFrame?
What happens when you slice an array using negative indexes?
What happens when you slice an array using negative indexes?
What command is used to install Pandas in Python?
What command is used to install Pandas in Python?
When slicing a 2D array with the notation arr[0:2, 1:4], what part of the array do you retrieve?
When slicing a 2D array with the notation arr[0:2, 1:4], what part of the array do you retrieve?
Which of the following correctly demonstrates how to create a Pandas DataFrame from a dictionary of cars and their corresponding passing values?
Which of the following correctly demonstrates how to create a Pandas DataFrame from a dictionary of cars and their corresponding passing values?
What is the output of the following Pandas Series creation: pd.Series(a, index = ['x', 'y', 'z'])
where a = [1, 7, 2]
?
What is the output of the following Pandas Series creation: pd.Series(a, index = ['x', 'y', 'z'])
where a = [1, 7, 2]
?
How can you create a one-dimensional NumPy array given a list of numeric values like [12.23, 13.32, 100, 36.32]
?
How can you create a one-dimensional NumPy array given a list of numeric values like [12.23, 13.32, 100, 36.32]
?
What is the result of the following operation: myvar = pd.Series(calories, index=['day1', 'day2'])
where calories = {'day1': 420, 'day2': 380, 'day3': 390}
?
What is the result of the following operation: myvar = pd.Series(calories, index=['day1', 'day2'])
where calories = {'day1': 420, 'day2': 380, 'day3': 390}
?
Which command correctly initializes an 8x8 matrix filled with a checkerboard pattern in NumPy?
Which command correctly initializes an 8x8 matrix filled with a checkerboard pattern in NumPy?
What command is used to create a 1-D array with the values 1, 2, 3, 4, 5?
What command is used to create a 1-D array with the values 1, 2, 3, 4, 5?
How do you correctly slice a NumPy array to obtain elements from index 1 to 3?
How do you correctly slice a NumPy array to obtain elements from index 1 to 3?
Which of the following is the correct way to import NumPy using an alias?
Which of the following is the correct way to import NumPy using an alias?
Which command correctly creates a 3-D NumPy array?
Which command correctly creates a 3-D NumPy array?
What will be the output of accessing the element at arr[0, 1, 2] for the array defined as arr = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])?
What will be the output of accessing the element at arr[0, 1, 2] for the array defined as arr = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])?
What is the shape of the array created by arr = np.array([[1, 2], [3, 4], [5, 6]])?
What is the shape of the array created by arr = np.array([[1, 2], [3, 4], [5, 6]])?
Which function is used to create a 2-D array containing two distinct 1-D arrays?
Which function is used to create a 2-D array containing two distinct 1-D arrays?
Using NumPy, how can you change the first row of a 2-D array arr = np.array([[1, 2, 3], [4, 5, 6]]) to [7, 8, 9]?
Using NumPy, how can you change the first row of a 2-D array arr = np.array([[1, 2, 3], [4, 5, 6]]) to [7, 8, 9]?
Flashcards
NumPy
NumPy
A Python library for numerical computations, particularly working with arrays.
NumPy array
NumPy array
The fundamental data structure in NumPy, an n-dimensional array of a given type.
1-D array
1-D array
A single row or column of numeric data.
2-D array
2-D array
Signup and view all the flashcards
3-D array
3-D array
Signup and view all the flashcards
Array Slicing
Array Slicing
Signup and view all the flashcards
ndarray
ndarray
Signup and view all the flashcards
Import NumPy
Import NumPy
Signup and view all the flashcards
Pandas Series
Pandas Series
Signup and view all the flashcards
Series Indexing
Series Indexing
Signup and view all the flashcards
Creating a Pandas Series
Creating a Pandas Series
Signup and view all the flashcards
Series element access
Series element access
Signup and view all the flashcards
NumPy Array Slicing
NumPy Array Slicing
Signup and view all the flashcards
Array Slicing: Start Index Omitted
Array Slicing: Start Index Omitted
Signup and view all the flashcards
Array Slicing: End Index Omitted
Array Slicing: End Index Omitted
Signup and view all the flashcards
Array Slicing: Negative Indices
Array Slicing: Negative Indices
Signup and view all the flashcards
Array Slicing: Step Value
Array Slicing: Step Value
Signup and view all the flashcards
Multi-dimensional Array Slicing
Multi-dimensional Array Slicing
Signup and view all the flashcards
Pandas DataFrame
Pandas DataFrame
Signup and view all the flashcards
Study Notes
NumPy
- NumPy is short for "Numerical Python"
- It's a Python library used for working with arrays.
NumPy Installation
- Install using pip:
C:\Users\Your Name>pip install --upgrade pip
C:\Users\Your Name>pip install numpy
Importing NumPy
- Import using
import numpy as np
- Create an array:
arr = np.array([1, 2, 3, 4, 5])
NumPy as np
- NumPy is typically imported as
np
- Example:
import numpy as np
Creating NumPy Arrays from tuples
- Using tuples to create NumPy arrays:
arr = np.array((1, 2, 3, 4, 5))
1-D Arrays
- Create a
1-D
array:arr = np.array([1, 2, 3, 4, 5])
Accessing Array Elements
- Accessing elements:
arr[0]
(first element from array)arr[1]
(second element from array)
2-D Arrays
- Create a
2-D
array:arr = np.array([[1, 2, 3], [4, 5, 6]])
Accessing 2-D Array elements
- Accessing specific elements:
arr[0, 1]
(2nd element in the first row)
3-D Arrays
- Create a
3-D
array:arr = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])
Accessing 3-D Array elements
- Accessing specific elements:
arr[0, 1, 2]
(third element in the second array from the first array)
NumPy Array Slicing
- Slicing extracts elements from a NumPy array
- Basic slicing:
arr[start:end]
arr[1:5]
slices items from index 1 up to (but not including) 5.
- Slicing with step:
arr[start:end:step]
arr[1:5:2]
slices elements from index 1 to 5 with a step of 2.
- Slicing to end of array:
arr[start:]
arr[4:]
starts at index 4 and goes to the end
- Slicing from beginning:
arr[:end]
arr[:4]
starts at beginning and goes up to (but not including) 4.
- Different slicing approaches with 2-D arrays.
- Slicing from indexes or a range of indexes of 2-D arrays.
Pandas
- Pandas is a Python library for data analysis
- It's used for manipulating and analyzing data sets.
Pandas Installation
- Install using pip:
pip install --upgrade pip
pip install pandas
Pandas DataFrames
- DataFrames are multi-dimensional tabular data structures.
- Series are one-dimensional arrays.
- Example DataFrame creation from a dictionary:
myvar = pd.DataFrame(data)
Pandas Series
- A Pandas Series is like a column in a table.
- It's a one-dimensional array holding data of any type.
Creating Pandas Series
- Create a Series from a list:
myvar = pd.Series([1, 7, 2])
- Create a Series from a dictionary:
myvar = pd.Series({"day1": 420, "day2": 380})
Accessing Series elements
- Accessing elements:
print(myvar[0])
Pandas Labels
- Labels can be used to access values.
- Default labels are index numbers.
- User defined labels are possible:
myvar = pd.Series([1, 7, 2], index=["x", "y", "z"])
- Key value pairs can also be used to create a Series
NumPy to One-Dimensional array
- Convert a list to a one-dimensional NumPy array:
np.array([12.23, 13.32, 100, 36.32])
NumPy to Array Range
- Create a NumPy array with values from 12 to 38:
np.arange(12, 39)
NumPy Checkerboard Pattern
- Create an 8x8 matrix with checkerboard pattern using NumPy.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.