Question

In: Computer Science

can you please create the code program in PYTHON for me. i want to create array...

can you please create the code program in PYTHON for me.

i want to create array matrix Nx1 (N is multiple of 4 and start from 16), and matrix has the value of elements like this:

if N = 16, matrix is
[ 4 4 4 4 -4 -4 -4 -4 4 4 4 4 -4 -4 -4 -4]

if N = 64, matrix is
[8 8 8 8 8 8 8 8 -8 -8 -8 -8 -8 -8 -8 -8 8 8 8 8 8 8 8 8 -8 -8 -8 -8 -8 -8 -8 -8 8 8 8 8 8 8 8 8 -8 -8 -8 -8 -8 -8 -8 -8 8 8 8 8 8 8 8 8 -8 -8 -8 -8 -8 -8 -8 -8]

if N = 256, matrix is
[16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -6 -16 -16 -16 -16 -16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -6 -16 -16 -16 -16 -16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -6 -16 -16 -16 -16 -16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -6 -16 -16 -16 -16 -16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -6 -16 -16 -16 -16 -16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -6 -16 -16 -16 -16 -16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -6 -16 -16 -16 -16 -16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -6 -16 -16 -16 -16 -16]

and so on for N = 1024, 4096, etc

please paste the code.

Solutions

Expert Solution

# PLEASE Read all the comments

import math # For sqrt of input number

def printResult(num): # This is function to print the result
num = int(math.sqrt(num)) ## Get the sqrt of number
numPositive = str(num) # String for positive char like 4
numNegative = str(-num) # String for negative char like -4
## Set the positive string and negative string
for i in range(0,num-1):
numPositive = numPositive + ' ' + str(num) # StringList for positive char like 4 4 4 4
numNegative = numNegative + ' -' + str(num) # StringList for negative char like -4 -4 -4 -4
numList = numPositive + ' ' + numNegative + ' ' # for a pair of output like 4 4 4 4 -4 -4 -4 -4
ansList = '' # for the list for answer
for i in range(0,int(num/2)): # Print result for num/2 times pair
ansList = ansList + numList # append the pair in ansList
print('[' + ansList +']') # print the result


print('Enter value') # Show input line
n = int(input()) # Get the input
printResult(n) # Print the result with given by calling function
  
  


# See the output


Related Solutions

In python using tkinter, I want to create a program. The program can have various classes...
In python using tkinter, I want to create a program. The program can have various classes and methods but I want it to have circles, triangles, and squares. Each shape movies in a certain way, like circles can move linearly, triangles can be affected by gravity, and squares can only go up and down. If the shapes get too close to one another then they disappear and a new shape appears somewhere else. I want this program to run continuously.
Code in python Hello I want a program to read only the price of each line...
Code in python Hello I want a program to read only the price of each line in a txt file in python. The price is present right after the 2nd comma within the txt file. The output that I want is also printed at the bottom. Inside the txt file: 2019-08-01 00:08:39,BTC/USD,10128.08 2019-08-01 00:08:21,BTC/USD,10117.54 2019-08-01 00:08:20,BTC/USD,10120.51 2019-08-01 00:08:19,BTC/USD,10118.13 2019-08-01 00:08:18,BTC/USD,10120.74 Python file output: Price 1: 10128.08 Price 2: 10117.54 Price 3: 10120.51 Price 4: 10118.13 Price 5: 10120.74
I want to create an image compression program with matlab use PCA. I have the code...
I want to create an image compression program with matlab use PCA. I have the code listed below. But this code is fail, the image is colorless, but still gray. Can you help me to fix my code. clc clear all picture = im2double(imread('picture1.jpg')); Red = picture(:,:,1); premean = mean(Red(:)); premax = max(Red(:)); premin = min(Red(:)); x = size(Red,1); y = size(Red,2); Z = ones(x,y)*premean; A = (Red - Z)*(1/premax - premin); B = cov(A); [veceig,eig,C] = pcacov(B); NewRed =...
Using Python code create a program only with beginners code. You are taking online reservations at...
Using Python code create a program only with beginners code. You are taking online reservations at the The inn Ask for your client’s name and save in a variable Ask how many nights your client will be staying and save in a variable Room rental is $145 per night Sales tax is 8.5% Habitation tax is $5 per night (not subject to sales tax) Print out: Client’s name Room rate per night Number of nights Room cost (room rate *...
Can someone please explain to me why "return 1" in this Python code returns the factorial...
Can someone please explain to me why "return 1" in this Python code returns the factorial of a given number? I understand recursion, but I do not understand why factorial(5) returns 120 when it clearly says to return 1. def factorial(n): if n == 0: return 1 else: return n * factorial(n-1)
I am having a trouble with a python program. I am to create a program that...
I am having a trouble with a python program. I am to create a program that calculates the estimated hours and mintutes. Here is my code. #!/usr/bin/env python3 #Arrival Date/Time Estimator # # from datetime import datetime import locale mph = 0 miles = 0 def get_departure_time():     while True:         date_str = input("Estimated time of departure (HH:MM AM/PM): ")         try:             depart_time = datetime.strptime(date_str, "%H:%M %p")         except ValueError:             print("Invalid date format. Try again.")             continue        ...
Writing python code: Can you do for me this. The question looks bellow Overview : As...
Writing python code: Can you do for me this. The question looks bellow Overview : As a programmer, you have be asked by a good friend to create a program that will allow them to keep track of their personal expenses. They want to be able to enter their expenses for the month, store them in a file, and then have the ability to retrieve them later. However, your friend only wants certain people to have the ability to view...
Please analyze and create a starter code in Python using spaCy, that can demonstrate practical use...
Please analyze and create a starter code in Python using spaCy, that can demonstrate practical use of the package. Also give a brief explanation of what the purpose of the spaCy package is. Please use 3 different methods such as a loop statement, if statement, tuples, lists etc. Please provide detailed comments on each line of code. Please explain the purpose of the method used. Please write and run your code example.
Python programming: can someone please fix my code to get it to work correctly? The program...
Python programming: can someone please fix my code to get it to work correctly? The program should print "car already started" if you try to start the car twice. And, should print "Car is already stopped" if you try to stop the car twice. Please add comments to explain why my code isn't working. Thanks! # Program goals: # To simulate a car game. Focus is to build the engine for this game. # When we run the program, it...
How do I make a dictionary in Python language? Can somebody please provide me with an...
How do I make a dictionary in Python language? Can somebody please provide me with an example code of a Dictionary in Python Language? Thank you in advance.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT