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
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)?...
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...
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...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program:...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program: Your program will create a username of your choice using a Kali Linux command "useradd -m mark", then set the password for that user using the Kali Linux Command "echo "mark:10101111" | chpasswd". Then you create a dictionary file using the Kali Linux command "crunch 8 8 01 > mylist.txt" Your python script should crack the password for that user and display on the...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called main that does the following: Creates a directory called CyberSecurity-Notes in the current working directory Within the CyberSecurity-Notes directory, creates 24 sub-directories (sub-folders), called Week 1, Week 2, Week 3, and so on until up through Week 24 Within each week directory, create 3 sub-directories, called Day 1, Day 2, and Day 3 Bonus Challenge: Add a conditional statement to abort the script if...
Write the following Python script: Imagine you live in a world without modules in Python! No...
Write the following Python script: Imagine you live in a world without modules in Python! No numpy! No scipy! Write a Python script that defines a function called mat_mult() that takes two lists of lists as parameters and, when possible, returns a list of lists representing the matrix product of the two inputs. Your function should make sure the lists are of the appropriate size first - if not, your program should print “Invalid sizes” and return None. Note: it...
Write the following Python script: Imagine you live in a world without modules in Python! No...
Write the following Python script: Imagine you live in a world without modules in Python! No numpy! No scipy! Write a Python script that defines a function called mat_mult() that takes two lists of lists as parameters and, when possible, returns a list of lists representing the matrix product of the two inputs. Your function should make sure the lists are of the appropriate size first - if not, your program should print “Invalid sizes” and return None. Note: it...
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this...
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this new matrix to a file called “Assignment3_Question5.dat”.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT