Grade 9, Week 1 - Numpy, 2D Arrays
Grade 9, Week 1 - Numpy, 2D Arrays
print(“ “ )
{
NumPy
Output
Changing a Python list to a NumPy Array
Output
Creating an array from user input
Output
Output
Output
Activity
https://wordwall.net/resource/21225484
Accessing data in a 2D Array
Output
Accessing rows and Columns
Colon “:” is How to print the column:
Let’s look at the same example- used to select
Let’s try to store Duaa’s data in
the starting and
an array
ending values
Output
Assigning New values to elements
https://wordwall.net/resource/21250840
Recap
https://wordwall.net/resource/35312339
Reshaping an array
Output
Transposing an array
The Transpose Function
Transpose changes each row to a
column and each column to a row.
a. Create a NumPy array for the information shown in the table above
Output
b. Reshape the array to (10,1) 10 rows, 1 column. Is this a better way to present the data?
This is not a good way to represent the data, as its names and seconds (10,1)
wouldn’t make sense.
c. Can you reshape the array to (4,3) 4 rows and 3 columns? If not, why
We cannot reshape the array to (4,3) for the same reason.
d. Reshape the elements of the array in a way that e. Transpose the array and write your observation on
makes the data easier to read (5 rows, 2 columns) the new shape
Recap