
code:
import numpy as np
def np1(n):
#getting values from 0 to n^2-1
#and then changing shape of array to matrix with nxn dimensions
res = np.arange(n*n).reshape(n,n)
return res
print(np1(2))
print(np1(3))
Problem 5 (5 points) Given an integer number, n, create a n by n matrix that...
import numpy as np
from scipy.special import comb
def cumulative_comb_with_repetition(n, k):
"""
Compute the number of possible non-negative, integer solutions
to
x1 + x2 + ... + xk <= n.
We will use this function to compute the dimension
of order k polynomial feature vector
Args:
n: integer, the number of "balls" or "stars"
k: integer, the number of "urns" or "bars"
Returns: the total number of combinations, integer.
"""
# your code below
# your code above...
Before you start For this homework, we will need to import some libraries. You need to execute the following cell only once; you don't need to copy this in every cell you run. In [ ]: import pandas import numpy from urllib.request import urlretrieve from matplotlib import pyplot %matplotlib inline #This library is needed for testing from IPython.display import set_matplotlib_close set_matplotlib_close(False) Introduction In this homework, you will work with data from the World Bank. The subject of study is...
def stochastic_gradient_descent(feature_matrix, label,
learning_rate = 0.05, epoch = 1000):
"""
Implement gradient descent algorithm for regression.
Args:
feature_matrix - A numpy matrix describing the given data, with
ones added as the first column. Each row
represents a single data point.
label - The correct value of response variable, corresponding to
feature_matrix.
learning_rate - the learning rate with default value 0.5
epoch - the number of iterations with default value 1000
Returns: A numpy array for the...
def gradient_descent(feature_matrix, label, learning_rate =
0.05, epoch = 1000):
"""
Implement gradient descent algorithm for regression.
Args:
feature_matrix - A numpy matrix describing the given data, with
ones added as the first column. Each row
represents a single data point.
label - The correct value of response variable, corresponding to
feature_matrix.
learning_rate - the learning rate with default value 0.5
epoch - the number of iterations with default value 1000
Returns: A numpy array for the...
Given an integer N as input, write a program to check whether Least Significant Bit (LSB) of a number is set or not. Use bitwise operator to solve the problem. Your code should NOT use conditional statement nor loop strucutre. Input: 5 where: First line represents the integer N. Output: Yes Here binary representation of 5 is 0101 and LSB is 1. Assumption: Value of N can be in the range 0 to 10000?
IN PYHTON CODE
Question #3 Produce a function prime_factors.dict that has one integer variable n that is assumed to be greater than 1. The function will return a dictionary with keys the integers from 2 to n, inclusive, and with values the set of prime factors of each key. So, the command prime_factors.dict (8) will return the dictionary 2 123,3: 3),4 2),5 (53,6 2,3),7:7),8 {2)) Note that even though the prime number 2 appears twice in the prime fac- torization...
Question A matrix of dimensions m × n (an m-by-n matrix) is an ordered collection of m × n elements. which are called eernents (or components). The elements of an (m × n)-dimensional matrix A are denoted as a,, where 1im and1 S, symbolically, written as, A-a(1,1) S (i.j) S(m, ). Written in the familiar notation: 01,1 am Gm,n A3×3matrix The horizontal and vertical lines of entries in a matrix are called rows and columns, respectively A matrix with the...
Use R programming to solve
Q2. A matrix operator H(G; k) on a pxp symmetric matrix G (iy)- with a positive integer parameter k (k < p) yields another p×p symmetric matrix H = (hij 1 with i=k,j = k; (a) Use one single loop to construct the function H(G; k) in R (b) Generate a random matrix X of dimension 7x5, each element of which is id from N(0,1). Use the function H(G; k constructed in (a) to compute...
Solve using Matlab. Provide actual code.
Create a 1000 x 4 matrix, with the first column switching between 0,1 (starting with 1), and the second column repeating itself in cycles of 1-2-3-4-5, the third column consisting of only 4's and the fourth column repeating itself in cycles of 0-1-2-3
Create a 1000 x 4 matrix, with the first column switching between 0,1 (starting with 1), and the second column repeating itself in cycles of 1-2-3-4-5, the third column consisting of...
4A. Write a CUDA host program that reads a character type matrix A and integer type matrix B of size mxn. It produces an output string STR such that, every character of A is repeated n times (where n is the integer value in matrix B which is having the same index as that of the character taken in A). Solve this using 1D Block. Example: 1 2 4 3 e X a M Output String STR: pCCaaaaPPPeeXXXXaaaMM 4B. Write...