Complete the code to shift the signal x by 3 units to the right.
import numpy as np x = np.array([1, 2, 3, 4, 5]) shifted_x = np.roll(x, [1]) print(shifted_x)
Using np.roll with 3 shifts the array elements 3 places to the right.
Complete the code to shift the signal x by 2 units to the left.
import numpy as np x = np.array([10, 20, 30, 40, 50]) shifted_x = np.roll(x, [1]) print(shifted_x)
Using np.roll with -2 shifts the array elements 2 places to the left.
Fix the error in the code to shift the signal x by 1 unit to the right.
import numpy as np x = [5, 10, 15, 20] shifted_x = np.roll([1], 1) print(shifted_x)
np.roll requires a numpy array, so convert the list x to an array first.
Fill both blanks to create a time-shifted signal by 2 units to the left and then multiply by 2.
import numpy as np x = np.array([1, 3, 5, 7, 9]) shifted_x = np.roll(x, [1]) * [2] print(shifted_x)
Shift left by 2 using -2, then multiply the shifted signal by 2.
Fill all three blanks to create a shifted signal by 1 unit right, then add 5 to each element, and finally divide by 2.
import numpy as np x = np.array([2, 4, 6, 8, 10]) result = (np.roll(x, [1]) + [2]) / [3] print(result)
Shift right by 1, add 5 to each element, then divide the result by 2.
