Question

In: Computer Science

Create and Compile a Python Script without using Numpy that Generate an nxn matrix using Python...

Create and Compile a Python Script without using Numpy that

  • Generate an nxn matrix using Python Script (ie n=user input)
  • Ask (user input ) and (randomly generated) row and column location
    • Assign Q to (known row and column location ) and 0 to all others location
  • Please show compile script working as well

Solutions

Expert Solution

CODE :

OUTPUT :

Raw_Code :

import random

n = int(input("Enter n : "))       #taking n and Q as input
Q = int(input("Enter Q : "))
matrix = []

row = random.randint(0,n-1)   #generating random row and column
column = random.randint(0,n-1)

for i in range(n):
   dup = []
   for j in range(n):           #creating matrix with zeros
       dup.append(0)
   matrix.append(dup)

matrix[row][column] = Q           #assign Q to known row and column

print("The Matrix is : ")
for i in range(n):               #printing matrix
   for j in range(n):
       print(matrix[i][j],end=' ')
   print()

***********Comment me for any Queries and Rate me up************


Related Solutions

Using Python: Normalize a 5x5 random matrix hints: use numpy create a random matrix X apply...
Using Python: Normalize a 5x5 random matrix hints: use numpy create a random matrix X apply Normalization: (X - Mean) / Deviation
inverse a matrix using pseudo inverse using python (numpy can be used) for a 2d list...
inverse a matrix using pseudo inverse using python (numpy can be used) for a 2d list (n x n).
Write a python code without using Sympy and Numpy to derive the polynomial 2x2 + 5x...
Write a python code without using Sympy and Numpy to derive the polynomial 2x2 + 5x + 4.
1 Linear Algebra in Numpy (1) Create a random 100-by-100 matrix M, using numpy method "np.random.randn(100,...
1 Linear Algebra in Numpy (1) Create a random 100-by-100 matrix M, using numpy method "np.random.randn(100, 100)", where each element is drawn from a random normal distribution. (2) Calculate the mean and variance of all the elements in M; (3) Use "for loop" to calculate the mean and variance of each row of M. (4) Use matrix operation instead of "for loop" to calculate the mean of each row of M, hint: create a vector of ones using np.ones(100, 1)?...
I need the following problem to be coded in python without using Numpy: Given input features...
I need the following problem to be coded in python without using Numpy: Given input features x1​, x2​,..., xi​ and corresponding weights w0​, w1​, w2​,...wi​. Write a function, called 'Perceptron', that returns the output value yi. For your function, use the following perceptron activation function: g(X,W)={1 if wTx>0;0 otherwise} The inputs X and W will be arrays of the input feature and weight values, respectively. All values will be integers. Your function will return gp​(X,W), which is a single integer...
Write and Compile a python script to solve the 4-queens problem using Forward Checking algorithm ....
Write and Compile a python script to solve the 4-queens problem using Forward Checking algorithm . The code should allow for random starting, and for placed starting. Random Starting means randomly place a queen position on the chessboard. Placed Starting means asked for the user input to place a queen position on the chessboard. Display the iterations until the final solution "The 4-Queens Problem[1] consists in placing four queens on a 4 x 4 chessboard so that no two queens...
Write and Compile a python script to solve the 4-queens problem using. The code should allow...
Write and Compile a python script to solve the 4-queens problem using. The code should allow for random starting, and for placed starting using numpy "The 4-Queens Problem[1] consists in placing four queens on a 4 x 4 chessboard so that no two queens can capture each other. That is, no two queens are allowed to be placed on the same row, the same column or the same diagonal." Display the iterations until the final solution Arc consistency
Using Python coding language (with or without Pandas and/or NumPy), 1. Can you define function sleep...
Using Python coding language (with or without Pandas and/or NumPy), 1. Can you define function sleep to tell whether the participant are of the ages through 18 to 60 and sleep less than 6 hours per day? 2. Develop codes to check whether the sleep function you defined can make correct judgement. Make sure you write comments or create informative vairable name so that I can understand how you check the sleep function. (Hints: You can create toy data/dataframe to...
need to write program on python, without using any other libraries like panda, numpy, etc. here...
need to write program on python, without using any other libraries like panda, numpy, etc. here is google link on csv file https://drive.google.com/file/d/1O3cC9JAPVkXSrddTR6RocpSV8NMHrmRx/view?usp=sharing There is a csv file, which is exel file, very big and what program should do: - Read a CSV file 'annual.csv' enterprise into a data structure - Count the number of rows and columns - Determine if the data contains empty values (should search in all rows) - Replace the empty values by 'NA' for strings,...
Develop a python program to - Create a 2D 10x10 numpy array and fill it with...
Develop a python program to - Create a 2D 10x10 numpy array and fill it with the random numbers between 1 and 9 (including 0 and 9). - Assume that you are located at (0,0) (upper-left corner) and want to move to (9,9) (lower-right corner) step by step. In each step, you can only move right or down in the array. - Develop a function to simulate random movement from (0,0) to (9,9) and return sum of all cell values...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT