IN PYTHON: Write a function that computes the outer product of two vectors WITHOUT using numpy / inbuilt functions.
For example, the outer product of [1,2,3] x [1,2] is
NOTE: I have completed answer for your question. Please check and let me know if you have any queries. I will get back to you within 24 hours. Thanks for your patience.
Code:
#!/usr/local/bin/python3
def out_prod(v1, v2):
'''
function which computes the vector
product of two given vectors
'''
# setting the header here
print('\nOuter Product')
print('===============')
print('i\k', end = ' ')
for elem in v2:
print("%5d" % elem, end = '
')
# drawing the double line
print('\n', '-'*25)
print('\n')
# calculating the outer product
for elem1 in v1:
print(elem1, end = ' ')
for elem2 in v2:
print("%5d" %
(elem1 * elem2), end = ' ')
print()
def main():
out_prod([1,2,3], [1,2])
out_prod([1,2], [1,2,3])
out_prod([1,2,3],[1,2,3])
if __name__=='__main__':
main()
Code screenshot:
Code output screenshot:
IN PYTHON: Write a function that computes the outer product of two vectors WITHOUT using numpy /&...
provide a python script please For the following vectors and matrices, using the NumPy library, write a script file that determines the solution for x given by the equation x-(A AT)b-Cd where AT denotes the transpose of A 1 2 3 4 16 12 8 4 A-2 4 6 8 3 6 9 12 4 8 12 16 C-12 9 6 3 8 6 4 2 4 3 2 1 4 The output to the command terminal prompt within Spyder...
Using Python using import numpy as np 3. Write a Python function that is passed a numeric grade from 0 to 100 and returns a letter grade according to the scheme shown in Table 1
Write a function in python that takes a set of vectors and returns the Gram-Schmidt orthonormal basis. This should include a check for linear independence. Use numpy.
ANSWER USING PYTHON Write a recursive function that takes 2 sorted lists as arguments and returns a single, merged sorted list as a result. For example, if the two input lists are [0, 2, 4, 6, 8] and [1, 3, 5, 7, 9], the returned result should be [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]. Remember that you can add lists in Python using the + operator ([0] + [1,2,3] = [0,1,2,3]) and can take slices of...
PYTHON: (Sum the digits in an integer using recursion) Write a recursive function that computes the sum of the digits in an integer. Use the following function header: def sumDigits(n): For example, sumDigits(234) returns 9. Write a test program that prompts the user to enter an integer and displays the sum of its digits. Sample Run Enter an integer: 231498 The sum of digits in 231498 is 27
Using python 3.6.0 Write a function, called cubic, which takes in two parameters, say x and y and computes the following formula: x3 + x + y and returns the computed value. Sample output 1: Enter x: 2 Enter y: 1 The value of the function is : 11 Sample output 2: Enter x: 1 Enter y: 3 The value of the function is : 5
1 [Run Lengths] Write a function (in Python and numpy) with the following specification def run_lenths(n, p): """Return a list of the run lengths in n tosses of a coin whose heads probability is p. Arguments: n--Number of tosses (a positive int), p--The probability of observing heads for any given toss (float between 0 and 1). """ For example, if the simulated sequence of coin tosses is HTTHHTHHHTTHHTTTTH, then the list of run lengths the function returns will be [1,...
[MATLAB] Write a function called myMultProd.m that computes the cumulative product of the elements in a vector. The cumulative product, pj, of the jth element of the vector x, xj, is defined by pj = (x1)(x2) … (xj) for j = 1:length of the vector x. DO NOT USE CUMPROD For example, when you run your function it should look like this: >> x = [2 3 4 2]; >> myMultProd(x) >> ans = 2 6 24 48 That is,...
using python with only using import math and copy no other powerful functions. Write a function defined as: def GaussSeidel(Aaug, x, Niter = 15): Purpose: use the Gauss-Seidel method to estimate the solution to a set of N linear equations expressed in matrix form as Ax = b. Both A and b are contained in the function argument – Aaug. Aaug: an augmented matrix containing [A | b ] having N rows and N+1 columns, where N is the number...
a)Write a Python function product(a, b) that recursively computes and returns the value of a times b. Use only the addition operator, and do not use any loops. You can assume that both parameters are non-negative integers. b)Use induction to prove that your algorithm from the previous part is correct