From b71171a7aa0ee7b0ed7532c1f82ef20437c8f06b Mon Sep 17 00:00:00 2001 From: suhanigarg29 <96908018+suhanigarg29@users.noreply.github.com> Date: Fri, 4 Feb 2022 14:52:35 +0530 Subject: [PATCH 01/13] Update Python_Exercises.py --- Python_Exercises.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Python_Exercises.py b/Python_Exercises.py index d7e6135..d8db3c2 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -7,8 +7,10 @@ def power(a,b): # ** What is 7 to the power of 4?** - - return None + + return a**b +out= power(7,4) +print(out) @@ -20,7 +22,9 @@ def split_str(s): # # **into a list. ** - return None + return s.split() +output= split_str("Hi there Sam!") +print(output) def format(planet,diameter): @@ -35,7 +39,7 @@ def format(planet,diameter): # The diameter of Earth is 12742 kilometers. return None - +print("The diameter of {planet} is {diameter} kilometers." .format(planet='Earth', diameter='12742')) def indexing(lst): @@ -43,8 +47,11 @@ def indexing(lst): # ** Given this nested list, use indexing to grab the word "hello" ** #lst = [1,2,[3,4],[5,[100,200,['hello']],23,11],1,7] + return None +lst = [1,2,[3,4],[5,[100,200,['hello']],23,11],1,7] +lst[3][1][2] - return None + def dictionary(d): @@ -55,6 +62,8 @@ def dictionary(d): return None +d = {'k1':[1,2,3,{'tricky':['oh','man','inception',{'target':[1,2,3,'hello']}]}]} +d['k1'][3]['tricky'][3]['target'][3] def subjective(): @@ -63,7 +72,7 @@ def subjective(): # Tuple is _______ return None - +immutable From 63aec225e297ee455318bbaf67e3f41bdef7ced4 Mon Sep 17 00:00:00 2001 From: suhanigarg29 <96908018+suhanigarg29@users.noreply.github.com> Date: Fri, 4 Feb 2022 15:36:26 +0530 Subject: [PATCH 02/13] Update Python_Exercises.py --- Python_Exercises.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Python_Exercises.py b/Python_Exercises.py index d8db3c2..2f9c0c9 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -113,7 +113,8 @@ def lambdafunc(seq): # ['soup','salad'] return None - +seq = ['soup','dog','salad','cat','great'] +list(filter(lambda x: x.startswith('s'), seq)) def caught_speeding(speed, is_birthday): @@ -125,7 +126,20 @@ def caught_speeding(speed, is_birthday): # cases. ** return None - + if is_birthday== False: + if speed<=60: + print("No Ticket") + elif speed>60 and speed<=80: + print("Small Ticket") + elif speed>80: + print("Big Ticket") + else: + if speed<=65: + print("No Ticket") + elif speed>65 and speed<=85: + print("Small Ticket") + elif speed>85: + print("Big Ticket") ## Numpy Exercises From 8219904354983811db9353c52d5ee20f8ef584ed Mon Sep 17 00:00:00 2001 From: suhanigarg29 <96908018+suhanigarg29@users.noreply.github.com> Date: Sat, 5 Feb 2022 20:03:25 +0530 Subject: [PATCH 03/13] Update Python_Exercises.py --- Python_Exercises.py | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/Python_Exercises.py b/Python_Exercises.py index 2f9c0c9..96516dc 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -84,14 +84,19 @@ def domainGet(email): # # **So for example, passing "user@domain.com" would return: domain.com** - return None + return email.split('@')[1] + def findDog(st): # ** Create a basic function that returns True if the word 'dog' is contained in the input string. Don't worry about edge cases like a punctuation being attached to the word dog, but do account for capitalization. ** - - return None + if 'dog' in st: + print("True") + else: + print("False") + return None +findDog("no dog here") def countDog(st): @@ -114,7 +119,7 @@ def lambdafunc(seq): return None seq = ['soup','dog','salad','cat','great'] -list(filter(lambda x: x.startswith('s'), seq)) +list(filter(lambda item: item.startswith('s'), seq)) def caught_speeding(speed, is_birthday): @@ -138,7 +143,7 @@ def caught_speeding(speed, is_birthday): print("No Ticket") elif speed>65 and speed<=85: print("Small Ticket") - elif speed>85: + else: print("Big Ticket") ## Numpy Exercises @@ -152,6 +157,10 @@ def create_arr_of_fives(): #### Convert your output into list #### e.g return list(arr) +a= np.random.randint(5,6,10) +a +a.tolist() + return None @@ -161,6 +170,9 @@ def even_num(): ### Create an array of all the even integers from 10 to 50 ### Convert your output into list ### e.g return list(arr) +a= np.arange(10,51,2) +a +a.tolist() return None @@ -171,6 +183,9 @@ def create_matrix(): ### Create a 3x3 matrix with values ranging from 0 to 8 ### Convert your output into list ### e.g return (arr).tolist() +a= np.random.randint(0,8,[3,3]) +a +a.tolist() return None @@ -181,6 +196,9 @@ def linear_space(): ### Create an array of 20 linearly spaced points between 0 and 1 ### Convert your output into list ### e.g return list(arr) +arr= np.linspace(0,1,20) +arr +arr.tolist() return None @@ -192,6 +210,7 @@ def decimal_mat(): ### Convert your output into list ### e.g return (arr).tolist() + return None @@ -212,6 +231,8 @@ def slices_1(): # array([[12, 13, 14, 15], # [17, 18, 19, 20], # [22, 23, 24, 25]]) +a= arr[2: ,1: ] +a.tolist() return None @@ -233,7 +254,8 @@ def slices_2(): # array([[ 2], # [ 7], # [12]]) - +a= arr[0:3,1:2] +a.tolist() return None @@ -254,6 +276,8 @@ def slices_3(): # array([[16, 17, 18, 19, 20], # [21, 22, 23, 24, 25]]) + a= arr[3: , 0:] + a.tolist() return None From 1bc7c451f73cad115571637e65d1cbbb859bf175 Mon Sep 17 00:00:00 2001 From: suhanigarg29 <96908018+suhanigarg29@users.noreply.github.com> Date: Sun, 6 Feb 2022 18:33:42 +0530 Subject: [PATCH 04/13] Update Python_Exercises.py --- Python_Exercises.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Python_Exercises.py b/Python_Exercises.py index 96516dc..306abe6 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -209,6 +209,9 @@ def decimal_mat(): ### Create an array of size 10*10 consisting of numbers from 0.01 to 1 ### Convert your output into list ### e.g return (arr).tolist() +arr= np.arange(0.01,1.0001,0.01).reshape(10,10) +arr +arr.tolist() return None From 9376a2f1c7f1468164af81adab0ee42bdb3389e8 Mon Sep 17 00:00:00 2001 From: suhanigarg29 <96908018+suhanigarg29@users.noreply.github.com> Date: Sun, 6 Feb 2022 18:51:32 +0530 Subject: [PATCH 05/13] Update Python_Exercises.py --- Python_Exercises.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Python_Exercises.py b/Python_Exercises.py index 306abe6..0d6b2fa 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -131,20 +131,20 @@ def caught_speeding(speed, is_birthday): # cases. ** return None - if is_birthday== False: + if is_birthday== False: if speed<=60: - print("No Ticket") + print("No Ticket") elif speed>60 and speed<=80: - print("Small Ticket") + print("Small Ticket") elif speed>80: print("Big Ticket") - else: - if speed<=65: - print("No Ticket") - elif speed>65 and speed<=85: - print("Small Ticket") else: - print("Big Ticket") + if speed<=65: + print("No Ticket") + elif speed>65 and speed<=85: + print("Small Ticket") + else: + print("Big Ticket") ## Numpy Exercises From 18804b8c27092ac3730f5be06d52581b068d1644 Mon Sep 17 00:00:00 2001 From: suhanigarg29 <96908018+suhanigarg29@users.noreply.github.com> Date: Sun, 6 Feb 2022 18:54:11 +0530 Subject: [PATCH 06/13] Update Python_Exercises.py --- Python_Exercises.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python_Exercises.py b/Python_Exercises.py index 0d6b2fa..b5db035 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -131,7 +131,7 @@ def caught_speeding(speed, is_birthday): # cases. ** return None - if is_birthday== False: +if is_birthday== False: if speed<=60: print("No Ticket") elif speed>60 and speed<=80: From f30a75b890b90bc864227eb9250e0a3d1f6fa31f Mon Sep 17 00:00:00 2001 From: suhanigarg29 <96908018+suhanigarg29@users.noreply.github.com> Date: Sun, 6 Feb 2022 18:58:00 +0530 Subject: [PATCH 07/13] Update Python_Exercises.py --- Python_Exercises.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Python_Exercises.py b/Python_Exercises.py index b5db035..c3d935c 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -183,11 +183,11 @@ def create_matrix(): ### Create a 3x3 matrix with values ranging from 0 to 8 ### Convert your output into list ### e.g return (arr).tolist() -a= np.random.randint(0,8,[3,3]) -a -a.tolist() + a= np.random.randint(0,8,[3,3]) + a + a.tolist() - return None + return None From 31e321d5510dfc93c6db96805056db06d90eda66 Mon Sep 17 00:00:00 2001 From: suhanigarg29 <96908018+suhanigarg29@users.noreply.github.com> Date: Sun, 6 Feb 2022 19:08:53 +0530 Subject: [PATCH 08/13] Update Python_Exercises.py --- Python_Exercises.py | 57 ++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/Python_Exercises.py b/Python_Exercises.py index c3d935c..dbda0b0 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -96,7 +96,6 @@ def findDog(st): else: print("False") return None -findDog("no dog here") def countDog(st): @@ -157,11 +156,11 @@ def create_arr_of_fives(): #### Convert your output into list #### e.g return list(arr) -a= np.random.randint(5,6,10) -a -a.tolist() + a= np.random.randint(5,6,10) + a + a.tolist() - return None + return None @@ -170,11 +169,11 @@ def even_num(): ### Create an array of all the even integers from 10 to 50 ### Convert your output into list ### e.g return list(arr) -a= np.arange(10,51,2) -a -a.tolist() + a= np.arange(10,51,2) + a + a.tolist() - return None + return None @@ -196,11 +195,11 @@ def linear_space(): ### Create an array of 20 linearly spaced points between 0 and 1 ### Convert your output into list ### e.g return list(arr) -arr= np.linspace(0,1,20) -arr -arr.tolist() + arr= np.linspace(0,1,20) + arr + arr.tolist() - return None + return None @@ -209,19 +208,19 @@ def decimal_mat(): ### Create an array of size 10*10 consisting of numbers from 0.01 to 1 ### Convert your output into list ### e.g return (arr).tolist() -arr= np.arange(0.01,1.0001,0.01).reshape(10,10) -arr -arr.tolist() + arr= np.arange(0.01,1.0001,0.01).reshape(10,10) + arr + arr.tolist() - return None + return None def slices_1(): # This is a given array - arr = np.arange(1,26).reshape(5,5) + arr = np.arange(1,26).reshape(5,5) # array([[ 1, 2, 3, 4, 5], # [ 6, 7, 8, 9, 10], # [11, 12, 13, 14, 15], @@ -234,17 +233,17 @@ def slices_1(): # array([[12, 13, 14, 15], # [17, 18, 19, 20], # [22, 23, 24, 25]]) -a= arr[2: ,1: ] -a.tolist() + a= arr[2: ,1: ] + a.tolist() - return None + return None def slices_2(): # This is a given array - arr = np.arange(1,26).reshape(5,5) + arr = np.arange(1,26).reshape(5,5) # array([[ 1, 2, 3, 4, 5], # [ 6, 7, 8, 9, 10], # [11, 12, 13, 14, 15], @@ -257,16 +256,16 @@ def slices_2(): # array([[ 2], # [ 7], # [12]]) -a= arr[0:3,1:2] -a.tolist() - return None + a= arr[0:3,1:2] + a.tolist() + return None def slices_3(): # This is a given array - arr = np.arange(1,26).reshape(5,5) + arr = np.arange(1,26).reshape(5,5) # array([[ 1, 2, 3, 4, 5], # [ 6, 7, 8, 9, 10], # [11, 12, 13, 14, 15], @@ -279,9 +278,9 @@ def slices_3(): # array([[16, 17, 18, 19, 20], # [21, 22, 23, 24, 25]]) - a= arr[3: , 0:] - a.tolist() - return None + a= arr[3: , 0:] + a.tolist() + return None # Great job! From 0c8097ca0075baf1c43370243c3e5c3859d3e1cf Mon Sep 17 00:00:00 2001 From: suhanigarg29 <96908018+suhanigarg29@users.noreply.github.com> Date: Sun, 6 Feb 2022 19:14:31 +0530 Subject: [PATCH 09/13] Update Python_Exercises.py --- Python_Exercises.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Python_Exercises.py b/Python_Exercises.py index dbda0b0..85ae5f3 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -14,6 +14,7 @@ def power(a,b): + def split_str(s): # ** Split this string:** From 2223aa2c1ea1c1cbdb57556adf2cb388c5166d61 Mon Sep 17 00:00:00 2001 From: suhanigarg29 <96908018+suhanigarg29@users.noreply.github.com> Date: Sun, 6 Feb 2022 19:21:57 +0530 Subject: [PATCH 10/13] Update Python_Exercises.py --- Python_Exercises.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Python_Exercises.py b/Python_Exercises.py index 85ae5f3..b28163c 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -73,7 +73,7 @@ def subjective(): # Tuple is _______ return None -immutable +print("immutable") @@ -137,14 +137,14 @@ def caught_speeding(speed, is_birthday): elif speed>60 and speed<=80: print("Small Ticket") elif speed>80: - print("Big Ticket") - else: - if speed<=65: - print("No Ticket") - elif speed>65 and speed<=85: - print("Small Ticket") - else: - print("Big Ticket") + print("Big Ticket") +else: + if speed<=65: + print("No Ticket") + elif speed>65 and speed<=85: + print("Small Ticket") + else: + print("Big Ticket") ## Numpy Exercises From 7eb4e45e7bdd3bdd4ed87795f8f38bbfe055d891 Mon Sep 17 00:00:00 2001 From: suhanigarg29 <96908018+suhanigarg29@users.noreply.github.com> Date: Sun, 6 Feb 2022 19:50:27 +0530 Subject: [PATCH 11/13] Update Python_Exercises.py --- Python_Exercises.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/Python_Exercises.py b/Python_Exercises.py index b28163c..4fadd9e 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -130,21 +130,17 @@ def caught_speeding(speed, is_birthday): # and 80 inclusive, the result is "Small Ticket". If speed is 81 or more, the result is "Big Ticket". Unless it is your birthday (encoded as a boolean value in the parameters of the function) -- on your birthday, your speed can be 5 higher in all # cases. ** - return None -if is_birthday== False: - if speed<=60: - print("No Ticket") - elif speed>60 and speed<=80: - print("Small Ticket") - elif speed>80: - print("Big Ticket") -else: - if speed<=65: - print("No Ticket") - elif speed>65 and speed<=85: - print("Small Ticket") - else: - print("Big Ticket") + if is_birthday: + speeding = speed - 5 + else: + speeding = speed + + if speeding > 80: + return 'Big Ticket' + elif speeding > 60: + return 'Small Ticket' + else: + return 'No Ticket' ## Numpy Exercises From 326130708da8919723ce7bf31d996784b5a71cf2 Mon Sep 17 00:00:00 2001 From: suhanigarg29 <96908018+suhanigarg29@users.noreply.github.com> Date: Sun, 6 Feb 2022 20:10:15 +0530 Subject: [PATCH 12/13] Update Python_Exercises.py --- Python_Exercises.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Python_Exercises.py b/Python_Exercises.py index 4fadd9e..3992bbd 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -40,7 +40,8 @@ def format(planet,diameter): # The diameter of Earth is 12742 kilometers. return None -print("The diameter of {planet} is {diameter} kilometers." .format(planet='Earth', diameter='12742')) +format("earth",12742) +print("The diameter of {} is {} kilometers." .format(planet, diameter)) def indexing(lst): From 79bd6c1ffcb41610117ae2a3946259ea24136db4 Mon Sep 17 00:00:00 2001 From: suhanigarg29 <96908018+suhanigarg29@users.noreply.github.com> Date: Sun, 6 Feb 2022 23:43:10 +0530 Subject: [PATCH 13/13] Update Python_Exercises.py --- Python_Exercises.py | 318 +++++++++++++++++++++----------------------- 1 file changed, 148 insertions(+), 170 deletions(-) diff --git a/Python_Exercises.py b/Python_Exercises.py index 3992bbd..a430cad 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -4,138 +4,133 @@ # Answer the questions or complete the tasks outlined in bold below. -def power(a,b): - +def power(a, b): # ** What is 7 to the power of 4?** - - return a**b -out= power(7,4) -print(out) + + return a ** b +out = power(7, 4) +print(out) def split_str(s): - # ** Split this string:** -# -# s = "Hi there Sam!" -# -# **into a list. ** + # + # s = "Hi there Sam!" + # + # **into a list. ** return s.split() -output= split_str("Hi there Sam!") + + +output = split_str("Hi there Sam!") print(output) -def format(planet,diameter): - -# ** Given the variables:** -# -# planet = "Earth" -# diameter = 12742 -# -# ** Use .format() to print the following string: ** -# -# The diameter of Earth is 12742 kilometers. +def format(planet, diameter): + # ** Given the variables:** + # + # planet = "Earth" + # diameter = 12742 + # + # ** Use .format() to print the following string: ** + # + # The diameter of Earth is 12742 kilometers. + + return "The diameter of {} is {} kilometers." .format(planet, diameter) + + +planet = "Earth" +diameter = 12742 - return None -format("earth",12742) -print("The diameter of {} is {} kilometers." .format(planet, diameter)) def indexing(lst): - -# ** Given this nested list, use indexing to grab the word "hello" ** + # ** Given this nested list, use indexing to grab the word "hello" ** + + # lst = [1,2,[3,4],[5,[100,200,['hello']],23,11],1,7] + return lst[3][1][2][0] -#lst = [1,2,[3,4],[5,[100,200,['hello']],23,11],1,7] - return None -lst = [1,2,[3,4],[5,[100,200,['hello']],23,11],1,7] -lst[3][1][2] - +lst = [1, 2, [3, 4], [5, [100, 200, ['hello']], 23, 11], 1, 7] + def dictionary(d): - -# ** Given this nested dictionary grab the word "hello". Be prepared, this will be annoying/tricky ** + # ** Given this nested dictionary grab the word "hello". Be prepared, this will be annoying/tricky ** + + # d = {'k1':[1,2,3,{'tricky':['oh','man','inception',{'target':[1,2,3,'hello']}]}]} -# d = {'k1':[1,2,3,{'tricky':['oh','man','inception',{'target':[1,2,3,'hello']}]}]} + return d['k1'][3]['tricky'][3]['target'][3] - return None -d = {'k1':[1,2,3,{'tricky':['oh','man','inception',{'target':[1,2,3,'hello']}]}]} +d = {'k1': [1, 2, 3, {'tricky': ['oh', 'man', 'inception', {'target': [1, 2, 3, 'hello']}]}]} d['k1'][3]['tricky'][3]['target'][3] def subjective(): - -# ** What is the main difference between a tuple and a list? ** -# Tuple is _______ + # ** What is the main difference between a tuple and a list? ** + # Tuple is _______ - return None -print("immutable") + return "immutable" def domainGet(email): - # ** Create a function that grabs the email website domain from a string in the form: ** -# -# user@domain.com -# -# **So for example, passing "user@domain.com" would return: domain.com** + # + # user@domain.com + # + # **So for example, passing "user@domain.com" would return: domain.com** return email.split('@')[1] - def findDog(st): - -# ** Create a basic function that returns True if the word 'dog' is contained in the input string. Don't worry about edge cases like a punctuation being attached to the word dog, but do account for capitalization. ** - if 'dog' in st: - print("True") - else: - print("False") - return None - + # ** Create a basic function that returns True if the word 'dog' is contained in the input string. Don't worry about edge cases like a punctuation being attached to the word dog, but do account for capitalization. ** -def countDog(st): + return 'dog' in st.lower().split() -# ** Create a function that counts the number of times the word "dog" occurs in a string. Again ignore edge cases. ** - return None +def countDog(st): + # ** Create a function that counts the number of times the word "dog" occurs in a string. Again ignore edge cases. ** + count = 0 + for word in st.lower().split(): + if word == 'dog': + count += 1 + return count def lambdafunc(seq): - # ** Use lambda expressions and the filter() function to filter out words from a list that don't start with the letter 's'. For example:** -# -# seq = ['soup','dog','salad','cat','great'] -# -# **should be filtered down to:** -# -# ['soup','salad'] + # + # seq = ['soup','dog','salad','cat','great'] + # + # **should be filtered down to:** + # + # ['soup','salad'] + + return a + + +seq = ['soup', 'dog', 'salad', 'cat', 'great'] +a= list(filter(lambda word: word[0] == 's', seq)) - return None -seq = ['soup','dog','salad','cat','great'] -list(filter(lambda item: item.startswith('s'), seq)) def caught_speeding(speed, is_birthday): - - -# **You are driving a little too fast, and a police officer stops you. Write a function -# to return one of 3 possible results: "No ticket", "Small ticket", or "Big Ticket". -# If your speed is 60 or less, the result is "No Ticket". If speed is between 61 -# and 80 inclusive, the result is "Small Ticket". If speed is 81 or more, the result is "Big Ticket". Unless it is your birthday (encoded as a boolean value in the parameters of the function) -- on your birthday, your speed can be 5 higher in all -# cases. ** + # **You are driving a little too fast, and a police officer stops you. Write a function + # to return one of 3 possible results: "No ticket", "Small ticket", or "Big Ticket". + # If your speed is 60 or less, the result is "No Ticket". If speed is between 61 + # and 80 inclusive, the result is "Small Ticket". If speed is 81 or more, the result is "Big Ticket". Unless it is your birthday (encoded as a boolean value in the parameters of the function) -- on your birthday, your speed can be 5 higher in all + # cases. ** if is_birthday: speeding = speed - 5 else: speeding = speed - + if speeding > 80: return 'Big Ticket' elif speeding > 60: @@ -143,142 +138,125 @@ def caught_speeding(speed, is_birthday): else: return 'No Ticket' + ## Numpy Exercises import numpy as np def create_arr_of_fives(): - - #### Create an array of 10 fives - #### Convert your output into list - #### e.g return list(arr) + #### Create an array of 10 fives + #### Convert your output into list + #### e.g return list(arr) - a= np.random.randint(5,6,10) + a = np.random.randint(5, 6, 10) a - a.tolist() - return None + return a.tolist() def even_num(): - - ### Create an array of all the even integers from 10 to 50 - ### Convert your output into list - ### e.g return list(arr) - a= np.arange(10,51,2) + ### Create an array of all the even integers from 10 to 50 + ### Convert your output into list + ### e.g return list(arr) + a = np.arange(10, 51, 2) a - a.tolist() - return None + return a.tolist() def create_matrix(): - - ### Create a 3x3 matrix with values ranging from 0 to 8 - ### Convert your output into list - ### e.g return (arr).tolist() - a= np.random.randint(0,8,[3,3]) + ### Create a 3x3 matrix with values ranging from 0 to 8 + ### Convert your output into list + ### e.g return (arr).tolist() + a = np.arange(0,9).reshape(3,3) a - a.tolist() - return None + return a.tolist() def linear_space(): - - ### Create an array of 20 linearly spaced points between 0 and 1 - ### Convert your output into list - ### e.g return list(arr) - arr= np.linspace(0,1,20) + ### Create an array of 20 linearly spaced points between 0 and 1 + ### Convert your output into list + ### e.g return list(arr) + arr = np.linspace(0, 1, 20) arr - arr.tolist() - return None + return arr.tolist() def decimal_mat(): - - ### Create an array of size 10*10 consisting of numbers from 0.01 to 1 - ### Convert your output into list - ### e.g return (arr).tolist() - arr= np.arange(0.01,1.0001,0.01).reshape(10,10) - arr - arr.tolist() + ### Create an array of size 10*10 consisting of numbers from 0.01 to 1 + ### Convert your output into list + ### e.g return (arr).tolist() + arr = np.around(np.linspace(0.01, 1., 100), decimals=2).reshape(10, 10).tolist() - return None - + return arr def slices_1(): - - # This is a given array - arr = np.arange(1,26).reshape(5,5) - # array([[ 1, 2, 3, 4, 5], - # [ 6, 7, 8, 9, 10], - # [11, 12, 13, 14, 15], - # [16, 17, 18, 19, 20], - # [21, 22, 23, 24, 25]]) + # This is a given array + arr = np.arange(1, 26).reshape(5, 5) + # array([[ 1, 2, 3, 4, 5], + # [ 6, 7, 8, 9, 10], + # [11, 12, 13, 14, 15], + # [16, 17, 18, 19, 20], + # [21, 22, 23, 24, 25]]) - # Write a code to slice this given array - ### Convert your output into list - ### e.g return (arr).tolist() - # array([[12, 13, 14, 15], - # [17, 18, 19, 20], - # [22, 23, 24, 25]]) - a= arr[2: ,1: ] - a.tolist() + # Write a code to slice this given array + ### Convert your output into list + ### e.g return (arr).tolist() + # array([[12, 13, 14, 15], + # [17, 18, 19, 20], + # [22, 23, 24, 25]]) + a = arr[2:, 1:] - return None + return a.tolist() def slices_2(): - - # This is a given array - arr = np.arange(1,26).reshape(5,5) - # array([[ 1, 2, 3, 4, 5], - # [ 6, 7, 8, 9, 10], - # [11, 12, 13, 14, 15], - # [16, 17, 18, 19, 20], - # [21, 22, 23, 24, 25]]) - - # Write a code to slice this given array - ### Convert your output into list - ### e.g return (arr).tolist() - # array([[ 2], - # [ 7], - # [12]]) - a= arr[0:3,1:2] - a.tolist() - return None + # This is a given array + arr = np.arange(1, 26).reshape(5, 5) + # array([[ 1, 2, 3, 4, 5], + # [ 6, 7, 8, 9, 10], + # [11, 12, 13, 14, 15], + # [16, 17, 18, 19, 20], + # [21, 22, 23, 24, 25]]) + + # Write a code to slice this given array + ### Convert your output into list + ### e.g return (arr).tolist() + # array([[ 2], + # [ 7], + # [12]]) + a = arr[0:3, 1:2] + return a.tolist() def slices_3(): - - # This is a given array - arr = np.arange(1,26).reshape(5,5) - # array([[ 1, 2, 3, 4, 5], - # [ 6, 7, 8, 9, 10], - # [11, 12, 13, 14, 15], - # [16, 17, 18, 19, 20], - # [21, 22, 23, 24, 25]]) - - # Write a code to slice this given array - ### Convert your output into list - ### e.g return (arr).tolist() - # array([[16, 17, 18, 19, 20], - # [21, 22, 23, 24, 25]]) - - a= arr[3: , 0:] - a.tolist() - return None - - -# Great job! + # This is a given array + arr = np.arange(1, 26).reshape(5, 5) + # array([[ 1, 2, 3, 4, 5], + # [ 6, 7, 8, 9, 10], + # [11, 12, 13, 14, 15], + # [16, 17, 18, 19, 20], + # [21, 22, 23, 24, 25]]) + + # Write a code to slice this given array + ### Convert your output into list + ### e.g return (arr).tolist() + # array([[16, 17, 18, 19, 20], + # [21, 22, 23, 24, 25]]) + + a = arr[3:, 0:] + + return a.tolist() + + # Great job!