Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
import numpy as np
import random
n = 10
X = np.random.randint(1, 20, n*n).reshape(n,n)
Y = np.random.randint(1, 20, n*n).reshape(n,n)
result = np.zeros(X. shape)
for i in range (len(X)):
for j in range (len(Y[0])):
for k in range (len (Y)):
result[i][j] += X[i][k] * Y[k][j]
result= result.reshape(-1,1)
a = 0
for r in result:
a = a + r
sum_value = a[0]
print("Total sum of all elements is {}".format(sum_value))
Complete analysis of this code and Big O
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 4 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- in java ecplise . Implement a program that randomly generates 10 integers from -100 to 100,stores them in a 1D array, and finds their maximum value. Calculate theexecution time of finding a maximum. Repeat the test for 10,000 and10,000,000 numbers. Provide your results in the form of a table below andprovide a small summary. Implement a Java program that will populate a 5x5 matrix with randomlygenerated integers from 0 to 100.(1) print your matrix in a table form.(2) modify your code to multiply all even numbers by 10 and print the matrix.Your output of questions (1) and (2) should match the format of the followingsample outputs:arrow_forwardimport numpy as npfrom scipy.optimize import minimizeimport matplotlib.pyplot as pltimport pickle #Implement the function regressionObjVal def regressionObjVal(w, X, y): # compute squared error (scalar) with respect # to w (vector) for the given data X and y # # Inputs: # w = d x 1 # X = N x d # y = N x 1 # Output: # error = scalar value (which is the error calcualted using objective function) # IMPLEMENT THIS METHOD - REMOVE THE NEXT LINE error = 0 return error #Implement the function regressionGradient def regressionGradient(w, X, y): # compute gradient of squared error (scalar) with respect # to w (vector) for the given data X and y # Inputs: # w = d x 1 # X = N x d # y = N x 1 # Output: # gradient = d length vector (not a d x 1 matrix) if len(w.shape) == 1: w = w[:,np.newaxis] # IMPLEMENT THIS METHOD - REMOVE THE NEXT LINE error_grad = np.zeros((X.shape[1],)) return error_grad…arrow_forwardfor given A and B s : import randomA = random.sample(range(0, 101), random.randint(1,100))A.sortprint(A)B = random.sample(range(0, 101), random.randint(1,100))B.sort(reverse=True)print(B) Conduct doubling experiments to compare the run time of selection vs. insertion sort (for both A and B). Plot the results (both case of array) for array sizes n = 2, 4, ... 1024. insertion and selection sort are provided below import timeimport numpy as np ### Selection Sort ###def selection_sort(A): for i in range(len(A)): min_idx = i for j in range(i + 1, len(A)): if A[min_idx] > A[j]: min_idx = j A[i], A[min_idx] = A[min_idx], A[i] return A ### Insertion Sort ###def insertion_sort(A): n = len(A) count = 0 for i in range(1,n): k = i while k > 0 and A[k] < A[k-1]: A[k], A[k-1] = A[k-1], A[k] k = k - 1 count += 1 return count, A provide code and resultarrow_forward
- You are given an integer n and an array of unique integers blacklist. Design an algorithm to pick a random integer in the range [0, n − 1] that is not in blacklist. Any integer that is in the mentioned range and not in blacklist should be equally likely to be returned. Optimize your algorithm such that it minimizes the number of calls to the built-in random function of your language.arrow_forwardConsider the two following random arrays "a" and "b": (10 points) a = np.random.randn (2, 3) # a.shape = (2, 3) b = np.random.randn (2, 1) # b.shape=(2, 1) c = a + b What will be the shape of "c"?arrow_forwardwrite a computer program that produces the desired output from the given input. Input: Elements in a finite set SOutput: Elements in ℘(S)Algorithm: Use recursion.arrow_forward
- Which among the following is the recursive definition of Factorial , i.e., n! ? f(0) = 1, f(n) = (n)f(n – 1), where n E Z andn 2 1. %D f(0) = 1, f (n) = (n + 1)f(n – 1), where n E Z and n > 1. f(0) = 0, f(n) = (n)f(n – 1), where n E Z and n > 1. %3D f (0) = 0, f(n) = (n + 1)f(n – 1), where n E Z and n 2 1.arrow_forwardimport randomN=8r=[ ]c=[ ]for i in range(1, N+1);r.append(random.choice (range(1, N+1)))c.append(random.choice(range(1, N+1)))print('Q{}: {},{}' . format(i,r[-1],c[-1]))print(r)print(c) The above code is used to initialize queens'positions in N Queen problem. Is there anypossibility that two queens will be placed inthe same position? a. Yesb. NOarrow_forwardConsider a set of random numbers IIDR [0,1] = [0.11,0.63,0.37,0.08,0.71,0.56,0.45,0.29,0.68]. Convert the set of random number to a set of random variates for N(0,1). Further convert this set of random variates to another set for N(5,3). Present the random numbers and the random variates in a Table as sought below. S.no IIDR[0,1] Random Variates for N(0,1) Random Variates for N(5,3)arrow_forward
- LeetCode Given an array of strings words representing an English Dictionary, return the longest word in words that can be built one character at a time by other words in words. If there is more than one possible answer, return the longest word with the smallest lexicographical order. If there is no answer, return the empty string. Example 1: Input: words = ["w","wo","wor","worl","wo Output: "world" Explanation: The word "world" can be buil Example 2: Input: words = ["a", "banana", "app","appl" Output: "apple" Explanation: Both "apply" and "apple" can Constraints: • 1 <= words.length <= 1000 • 1 <= words [i]. length <= 30 words [1] consists of lowercase English letters.arrow_forwardConsider the two following random arrays "a" and "b": a = np.random.randn (2, 3) # a.shape = (2, 3) b = np.random.randn (2, 1) # b.shape = (2, 1) c = a + b What will be the shape of "c"?arrow_forwardJAVA Make a function that will get the value of ln(n!). use Math.log() function in replace to ln()arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education