Question

In: Computer Science

In python import numpy as np Given the array b = np.arange(-6, 4) compute and print...

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.

Solutions

Expert Solution

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)

  


Related Solutions

UsePython (import numpy as np) use containers (Branching if statement, while loop, for loop, numpy Array)...
UsePython (import numpy as np) use containers (Branching if statement, while loop, for loop, numpy Array) Implement an algorithm to guess a random number that the computer generates. The random number must be an integer between 1 and 1000 (inclusive). For each unsuccessful attempt, the program must let the user know whether to deal with a higher number or more. low. There is no limit on the number of attempts, the game only ends when the user succeeds. The user...
Please I seek assistance Python Programing import os import numpy as np def generate_assignment_data(expected_grade_file_path, std_dev, output_file_path):...
Please I seek assistance Python Programing import os import numpy as np def generate_assignment_data(expected_grade_file_path, std_dev, output_file_path): """ Retrieve list of students and their expected grade from file, generate a sampled test grade for each student drawn from a Gaussian distribution defined by the student expected grade as mean, and the given standard deviation. If the sample is higher than 100, re-sample. If the sample is lower than 0 or 5 standard deviations below mean, re-sample Write the list of student...
import math import numpy as np import numpy.linalg from scipy.linalg import solve A = np.array([[-math.cos(math.pi/6),0, math.cos(math.pi/3),0,...
import math import numpy as np import numpy.linalg from scipy.linalg import solve A = np.array([[-math.cos(math.pi/6),0, math.cos(math.pi/3),0, 0, 0], [-math.sin(math.pi/6), 0, -math.sin(math.pi/3), 0, 0, 0], [math.cos(math.pi/6), 1, 0, 1, 0, 0], [math.sin(math.pi/6), 0, 0, 0, 1, 0], [0, -1, -math.cos(math.pi/3), 0, 0, 0], [0, 0, math.sin(math.pi/3), 0, 0, 1]]) b = np.array([0, 2000, 0, 0, 0, 0]) x = [0, 0, 0, 0, 0, 0] def seidel(a, x, b): # Finding length of a(3) n = len(a) # for loop for...
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...
# ArrayStack # TODO: push and pop using array stack with doubling technique. import numpy as...
# ArrayStack # TODO: push and pop using array stack with doubling technique. import numpy as np from future import print_function # Definisi class ArrayStack class ArrayStack(object): def __init__(self): self.data = np.zeros(20, dtype=np.int) self.count = 0 def isEmpty(self): pass # ubah saya def size(self): pass # ubah saya def push(self, obj): pass # ubah saya def pop(self): pass # ubah saya #-------------------------- # End of class if __name__ == "__main__": stack = ArrayStack() randn = np.random.permutation(1000) for i in range(1000):...
Using Python : Create a 4×5 4 × 5 array ? X with random value. Print...
Using Python : Create a 4×5 4 × 5 array ? X with random value. Print out ? X , as well as the largest value of each column.
Part A: Compute the derivative of ?(?)=(4?^4 + 2?)(?+9)(?−6) Part B: Compute the derivative of ?(?)=...
Part A: Compute the derivative of ?(?)=(4?^4 + 2?)(?+9)(?−6) Part B: Compute the derivative of ?(?)= (9x^2 + 8x +8)(4x^4 + (6/x^2))/x^3 + 8 Part C: Compute the derivative of ?(?)=(15?+3)(17?+13)/(6?+8)(3?+11).
Problem Definition: Problem: Given an array of integers print all pairs of integers a and b...
Problem Definition: Problem: Given an array of integers print all pairs of integers a and b where a + b is equal to a given number. For example, consider the following array and suppose we want to find all pairs of integers a and b where a + b = 16 A= [ 10, 4, 6, 15, 3, 5, 1, 13] The following are pairs that sum to 16: 13, 3 6, 10 15, 1 Your program should print these...
compute and print factorial if it is equal to 6, not equal to 6, and square...
compute and print factorial if it is equal to 6, not equal to 6, and square of the factorial, if the input is equal to 6 ..... C programming
What does each line of this python code do? import datetime import getpass print("\n\nFinished execution at...
What does each line of this python code do? import datetime import getpass print("\n\nFinished execution at ", datetime.datetime.now()) print(getpass.getuser())
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT