Question

In: Computer Science

Pycharm Write a function to make a new list 1. if original_samples is [1,2,3], then this...

Pycharm
Write a function to make a new list
1. if original_samples is [1,2,3], then this should return a new list [3,2,1]. Don't use the reversed function or original_samples[::-1]

def make_reserved_samples (original_samples):
new_samples[ ]
  
return new_samples

2. multiplied by volume. If original_samples is [1,2,3] and volume is 2, the new list is [2,4,6]

def make_louder_samples(original_samples, volume):

return [ ]

3. If the original list is [1,2,3,4,5,6,7,8] and skip is 3, the new liat should be [1,4,7]. Don't use original_list[::skip]. you must use a loop to find the desired elements.

def make_reduced_samples(original_samples, skip):

return[ ]

4. if original samples is [-5,-1,2,5,10] and clip level is 4, then new liat would be [-4,-1,2,4,4]

def make clipped_samples(original_samples, clip_level):

return [ ]

5. if the original list is [10,20,30] and noise_level is 2, the a new list is [8,21,29] if the random ints picked happened to be -2,-1,-1 return the new list

def make_noisy_samples(origianl_samples, noise_level):
return [ ]
6. write a function to make a tone. Each "sawtooth" should be valus going from -10000 to 10000 counting by 1000. So the elements should be -10000,-9000,-8000,-7000,-6000, .........., 7000,8000,9000,10000. Then there should be 1000 sawtooths.

def make_tone( ):
return [ ]


Solutions

Expert Solution

1.)

def make_reserved_samples (original_samples):
    c = len(original_samples)-1
    while c >= 0:
        new_samples.append(original_samples[c])
        c = c - 1
    return new_samples
original_samples=[1,2,3]
new_samples=[]
print(make_reserved_samples (original_samples))

2.)

def make_louder_samples(original_samples, volume):
    for o in original_samples:
        new_samples.append(o*volume)
    return new_samples
original_samples=[1,2,3]
new_samples=[]
print(make_louder_samples(original_samples,2))

3.)

def make_reduced_samples(original_samples, skip):
    new_list = []
    i = 0
    for a in original_samples:
        if i <= len(original_samples):
            new_list.append(original_samples[i])
            i += skip

    return new_list
original_samples=[1,2,3,4,5,6,7,8]
print(make_reduced_samples(original_samples,3))

4.)

import numpy as np 
def make_clipped_samples(original_samples, clip_level):
    new_list = np.clip(original_samples, a_min = - clip_level , a_max = clip_level) 

    return new_list
original_samples=[-5,-1,2,5,10] 
print(make_clipped_samples(original_samples,4))

I have provided solution for 4 questions.Hope it helps you


Related Solutions

Write a new MATLAB function as described in the following: 1. The new function will have...
Write a new MATLAB function as described in the following: 1. The new function will have three input parameters: f, W, C. 2. Parameter f will specify the frequency of the square wave. 3. The parameter W will specify the width of the single pulse as a number of sample periods. 4. The parameter C will specify the number of square wave cycles. 5. Calculate a number of samples, N, to run the simulation for both waveforms. 6. Create one...
1.Write a function div7(lst) which takes in a list of integers, and returns a list of...
1.Write a function div7(lst) which takes in a list of integers, and returns a list of booleans of the same length, such that for each integer in the original list, the boolean in the output list is True if that integer was divisible by 7, or False if not. Use list comprehensions in python, the function only could be at most two lines long. Here is some examples: >>> div7([14, 5, 7, 3, 29, 28, 10]) [True, False, True, False,...
Part A In PyCharm, write a program that prompts the user for their name and age....
Part A In PyCharm, write a program that prompts the user for their name and age. Your program should then tell the user the year they were born. Here is a sample execution of the program with the user input in bold: What is your name? Amanda How old are you? 15 Hello Amanda! You were born in 2005. Write the program. Format your code using best practices. Refer to the zyBooks style guide, if needed, to use proper naming...
RACKET a) Write a recursive function (gen-list start end). This function will generate a list of...
RACKET a) Write a recursive function (gen-list start end). This function will generate a list of consecutive integers, from start to end. If start > end then an empty list is generated. For example: (gen-list 1 5) ---> (1 2 3 4 5) b) write a recursive function pair-sum? that takes an integer sequence as generated by the gen-list function in exercise 4 above. This function tests whether any two adjacent values in the given list sum to the given...
Write a function that takes a list of integers as input and returns a list with...
Write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2] Do not use any special or built in functions like append, reverse etc.
Write a function that will accept a list of numbers and an integer (n). The function...
Write a function that will accept a list of numbers and an integer (n). The function should return a list containing every nth item from the input list, always starting with the first item in the list. The original list should not be modified. For example, if the function is passed the list [8, 3, 19, 26, 32, 12, 3, 7, 21, 16] and the integer 3, it will return the list [8, 26, 3, 16] If the function is...
1. Write a function named “Number” that reads in a list of numbers until the user...
1. Write a function named “Number” that reads in a list of numbers until the user enters 0. It will return true if the user has entered more even numbers than odd numbers; otherwise it returns false. 2. Write a code segment to sort an array of students in ascending order of their IDs. Assume the array has been filled with names and assume the following declaration: struct Student { string name; int ID; } Student roster[30]; // Code to...
PYTHON: Write a function insertInOrder that takes in a list and a number. This function should...
PYTHON: Write a function insertInOrder that takes in a list and a number. This function should assume that the list is already in ascending order. The function should insert the number into the correct position of the list so that the list stays in ascending order. It should modify the list, not build a new list. It does not need to return the list, because it is modifying it.   Hint: Use a whlie loop and list methods lst = [1,3,5,7]...
Write a Python function that takes a list of string as arguments. When the function is...
Write a Python function that takes a list of string as arguments. When the function is called it should ask the user to make a selection from the options listed in the given list. The it should get input from the user. Place " >" in front of user input. if the user doesn't input one of the given choices, then the program should repeatedly ask the user to pick from the list. Finally, the function should return the word...
We were asked this: Write a function that takes a list, and returns a list representing...
We were asked this: Write a function that takes a list, and returns a list representing each word whose reverse is also in the list. def find_reversals(lst: List[str]) -> List[str]: Each pair, such as 'abut', 'tuba', should be represented by the first element encountered. Don't report the same pairs twice. Don't list palindromes. I wrote this, which might not be optimal but passes the unit test! def find_reversals(lst): #Place to save to found_reversals=[]    #Make each string lowercase for i...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT