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

Could you create me a secant code in Matlab program? That's I can keep it and...
Could you create me a secant code in Matlab program? That's I can keep it and use it for any time?
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.
Can you fix to me this code plz I just want to print this method as...
Can you fix to me this code plz I just want to print this method as the reverse. the problem is not printing reverse. public void printBackward() {               Node curr = head;        Node prev = null;        Node next = null;               System.out.print("\nthe backward of the linkedlist is: ");               while(curr != null) {            next = curr.next;            curr.next = prev;   ...
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
can you please convert this python code into java? Python code is as shown below: #...
can you please convert this python code into java? Python code is as shown below: # recursive function def row_puzzle_rec(row, pos, visited):    # if the element at the current position is 0 we have reached our goal    if row[pos] == 0:        possible = True    else:        # make a copy of the visited array        visited = visited[:]        # if the element at the current position has been already visited then...
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 *...
I need someone to create a program for me: Create a program that takes as input...
I need someone to create a program for me: Create a program that takes as input an employee's salary and a rating of the employee's performance and computes the raise for the employee. The performance rating here is being entered as a String — the three possible ratings are "Outstanding", "Acceptable", and " Needs Improvement ". An employee who is rated outstanding will receive a 10.2 % raise, one rated acceptable will receive a 7 % raise, and one rated...
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)
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