Commit 2f978b60 authored by George Mount's avatar George Mount
Browse files

update files

parent f6d3aae4
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
### Drill ### Drill
Take a shot at assigning an array and finding its square root using this aliasing method. Take a shot at assigning an array and finding its square root using this aliasing method.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# Import and alias the module # Import and alias the module
import ___ ___ ___ import ___ ___ ___
# Create an array # Create an array
my_new_array = ___.___([36, 49, 64, 81]) my_new_array = ___.___([36, 49, 64, 81])
# Take its square root # Take its square root
np.___(___) np.___(___)
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# Import and alias the module # Import and alias the module
import numpy as np import numpy as np
# Create an array # Create an array
my_new_array = np.array([36, 49, 64, 81]) my_new_array = np.array([36, 49, 64, 81])
# Take its square root # Take its square root
np.sqrt(my_new_array) np.sqrt(my_new_array)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# DRILL # DRILL
Practice your `numpy` skills by operating on a large array. Practice your `numpy` skills by operating on a large array.
I will get you started; complete the operations based on what the comments are asking for. I will get you started; complete the operations based on what the comments are asking for.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# Don't worry about this part -- I am reading the file into Python. # Don't worry about this part -- I am reading the file into Python.
# You will learn how to read files into Python in the next unit. # You will learn how to read files into Python in the next unit.
my_array = np.genfromtxt('numpy-drill.csv') my_array = np.genfromtxt('numpy-drill.csv')
print(my_array) my_array
``` ```
%% Output
[47. 21. 23. 24. 45. 6. 30. 43. 45. 23. 2. 46. 4. 34. 42. 2. 47. 14.
18. 9. 50. 34. 12. 24. 42. 24. 3. 39. 17. 15. 37. 18. 46. 25. 9. 41.
45. 34. 22. 26. 27. 44. 28. 4. 15. 31. 3. 39. 15. 23. 5. 27. 11. 25.
16. 11. 2. 43. 35. 45. 27. 48. 44. 20. 4. 21. 8. 48. 29. 20. 15. 20.
37. 17. 6. 13. 39. 25. 5. 11. 4. 20. 47. 9. 2. 8. 44. 40. 8. 1.
45. 26. 43. 10. 22. 24. 3. 48. 29. 49.]
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# What is the shape of this array? # What is the shape of this array?
# This also tells us how many dimensions there are -- # This also tells us how many dimensions there are --
# one number means one dimension # one number means one dimension
my_array.shape my_array.shape
``` ```
%% Output
(100,)
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# What is its datatype? # What is its datatype?
my_array.dtype my_array.dtype
``` ```
%% Output
dtype('float64')
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# Reshape this result into a 10x10 array # Reshape this result into a 10x10 array
my_array = np.reshape(my_array, (10, 10)) my_array = np.reshape(my_array, (10, 10))
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# What is the shape of our array now? # What is the shape of our array now?
my_array.shape my_array.shape
``` ```
%% Output
(10, 10)
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python