In: Computer Science
In python
import numpy as np
Given the array b = np.arange(-6, 4) compute and print
1.) The array formed by \(bi^2 - 1\), where the \(bi\) are the elements of the array b.
2.) The array formed by multiplying b with the scalar 100.
3.)The array formed by 2.0 b i in reverse order. (Note: the base 2.0 must be a floating point number; for integer values a ValueError: Integers to negative integer powers are not allowed. is raised.)
4.) The array delta of length len(b)-1 that contains the differences between subsequence entries of \(bi^3\), namely \(\deltai = b{i+1}^3 - bi^3 \) with 0 ≤ i < N − 1 where N is the length of b. Print both delta.shape and delta.
import numpy as np
b = np.arange(-6, 4) # result : b = [-6 -5 -4 -3 -2 -1 0 1 2 3]
The array formed by \(bi^2 - 1\), where the \(bi\) are the elements of the array b.
result_array = []
for i in b:
result_array.append(i^2 - 1)
print(result_array)
The array formed by multiplying b with the scalar 100.
result_array = []
for i in b:
result_array.append(i*100)
print(result_array)
The array formed by 2.0 b i in reverse order.
def reverse(list):
return(element for element in reversed(list))
result_array = []
b = reverse(b)
for i in b:
result_array.append(b*2.0)
print(result_array)
The array delta of length len(b)-1 that contains the differences between subsequence entries of \(bi^3\), namely \(\deltai = b{i+1}^3 - bi^3 \) with 0 ≤ i < N − 1 where N is the length of b. Print both delta.shape and delta.
delta = []
result_array = []
for i in b:
result_array.append[i^3]
for i in range(len(b)-1):
delta.append(abs(result_array[i] - result_array[i+1]))
print(delta)