





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
PROBABILITY AND STATISTICS IN DATA SCIENCE USING PYTHON EXAM SOLVED #2
Typology: Exams
1 / 9
This page cannot be seen from the preview
Don't miss anything!






Import numpy - correct answer import numpy as np How to print out multiple stuff on one line - correct answer Use commas to separate the printed statements Print("Some string", a_variable) How to print multiple stuff and then print out space beneath the printed statement - correct answer Use '\n' Print("One Dimensional Array", x1, '\n') How to separate stuff from a printed statement into different paragraphs - correct answer Use sep='\n' Print("One Dimensional Array", x1, sep='\n') Two dimensional array - correct answer my_array= np.array([[3,4,5,6],[4,5,6,-9]]) How to return the number of dimensions an array has - correct answer x1.ndim Return the number of elements a in each dimension of an array - correct answer x1.shape Return the total number of elements across all dimensions of an array - correct answer x1.size How to tell the data types of elements in an array - correct answer float_array.dtype Return every third element of an array - correct answer my_array[::3] Return every other element, starting with the first element - correct answer my_array[1::2] How to reverse an array - correct answer numeric_array[::-1] How to add value to dictionary - correct answer No brackets on other side University_info['country'] = 'United States' University_info
Function rule - correct answer Always return, don't print How to sort with numpy - correct answer np.sort() For multidimensional arrays, specify axis Np.sort(my_array, axis=0) 0 sorts columns, and 1 sorts rows Nd_player_weights.sort() would sort the original values How to split up array according to your specs - correct answer np.split(my_array, [3,5,8]) Will split up values with indexes 0-2, then 3-4, then 5-7, then 8 beyond How to split an array into equal parts - correct answer np.array_split(my_array, 6) NO BRACKETS Six arrays with equal parts. It returns a list with the specified number of arrays inside of it Np.hsplit() - correct answer split_1, split_2 = np.hsplit(employee_salaries_grid, indices_or_sections=[3]) Print("First Split", split_1, sep='\n') Print("Second Split", split_2, sep='\n') OUT: First Split [[ 101442. 94122. 101592.] [ 87006. 102228. 84054.] [ 90024. 82614. 48078.] [ 76266. 68616. 62820.]] Second Split [[ 110064. 50436. 103350. 93354. 84054.] [ 91272. 111492. 95484. 114846. 63480.] [ 72510. 48078. 110064. 110064. 42108.] [ 128970. 48078. 89148. 101712. 70092.]] Np.vsplit() - correct answer split_1, split_2, split_3 = np.vsplit(employee_salaries_grid, [1, 3]) Print(split_1, split_2, split_3, sep='\n\n') OUT: [[ 101442. 94122. 101592. 110064. 50436. 103350. 93354. 84054.]]
If you want to fully reverse a multi-dimension array - correct answer two_dim_array[::- 1, ::-1] Only reverse columns - correct answer two_dim_array[:,::-1] When we use slice notation on an ndarray, it returns a view of the - correct answer original, as opposed to a copy Function will return true if any array values are True - correct answer np.any() The ____ function returns true if ALL the array values are true - correct answer np.all() Function will return the total number of True values in a boolean array - correct answer np.sum() Bitwise not operator - correct answer ~ Reverses values in boolean array Grab 32 elements of an array and reshape it - correct answer employee_salaries_grid = employee_salaries[:32].reshape(4, 8) Reshape - correct answer .reshape(3,4) Must have same number of elements What does simple_int_array + 5 do? - correct answer Adds five to each element of the array.
Simple_int_array - 10
Simple_int_array ** 3 - 10 Operations between two Numpy arrays - correct answer np.add(one_to_five, six_to_ten) One_to_five / six_to_ten
Being able to perform mathematical operations between two arrays is a really powerful tool. But, take note that this only works when you have two arrays of the same size and shape. Absolute Value - correct answer np.abs(two_dim_array_with_negative_values) Calculate 2 ** element for each element in the array - correct answer np.exp2(simple_int_array) Calculate (element ** 3) for each element in the array. - correct answer np.power(simple_int_array, 3) Base 10 Logarithm Base 2 Log - correct answer np.log10() Np.log2() Natural Log - correct answer np.log() How to sum columns - correct answer np.sum(salaries_4_by_5_grid, axis=0) How to sum rows - correct answer np.sum(salaries_4_by_5_grid, axis=1) Min alone and for each column - correct answer np.min(salaries_4_by_5_grid) Np.min(salaries_4_by_5_grid, axis=0) Max alone and for each row - correct answer np.max(salaries_4_by_5_grid) Np.max(salaries_4_by_5_grid, axis=1) Calculate the mean value of each row Mean alone - correct answer np.mean(salaries_4_by_5_grid, axis=1) Np.mean(salaries) Calculate the median value of each column Median alone - correct answer np.median(salaries_4_by_5_grid, axis=0) Standard Deviation - correct answer np.std() Percentile - correct answer np.percentile(salaries_4_by_5_grid, 90, axis=1) For centain axis Np.percentile(salaries, [34,67]) for multiple percentiles Np.percentile(salaries, 49)
Else: Print("Hello {}".format(name)) Continue - correct answer example_list = ['Hello', 245, 'Goodbye', 67] Continue stops processing the current item in a for loop and moves to the next item For element in example_list: If type(element) == str: Continue # No strings will be printed Print(element) OUT: 245, 67 Else clause - correct answer Under Try: Blah Except valueerror: Kdk Else: "I print if there is no exceptions" Basic string interpolation - correct answer "I really like {} and {}.".format('Chipotle', 'In-N- Out Burger') Advanced String Interpolation - correct answer example_list = [98, 57, 32, 94] "The first element in my list is {0[0]} and the last item is {0[3]}".format(example_list) T or F: The return statement will immediately stop all further processing and return whatever object(s) are specified after it. - correct answer True Def function_that_returns(): Return 5 Print('Hello') Function_that_returns() OUT: 5 T or F: Can return multiple values - correct answer True, just use commas Return 5, Function with default parameter - correct answer def function_with_default_parameter_values(value_1, value_2='Goodbye'):
Print("{0}, {1}!".format(value_1, value_2)) Tuple - correct answer Can't add or remove elements from them When you return stuff, they are stored in a tuple Def function_with_multiple_return_values(): Return 5, 8 Results = function_with_multiple_return_values() Results[0] OUT: 5 Np.where() - correct answer simple_array = np.array([10, 11, 12, 13, 14, 15, 16, 17]) Np.where(simple_array >= 14) (array([4, 5, 6, 7]),) Returns indexes How to replace stuff - correct answer .replace() Can chain with .replace().replace() How to make pandas index - correct answer chicago_crime.index = chicago_crime['CASE#'] Specify a data column to use as the index - correct answer index_col='institution_name' Use columns - correct answer usecols=[0, 1, 2] Column names - correct answer names=['obtuse_college_id', 'college_name', 'college_address'] Parse Dates - correct answer parse_dates=[['Date', 'Time (UTC)'] How to change elements in row slice - correct answer row_one[:] = [1, 2, 3] Remember, slices are not copies, they are views Euler's number - correct answer np.exp Raises elements to Euler's Number What is the actual class name of an array? - correct answer numpy.ndarray