Compute the average using a numpy function

Assignment Help Python Programming
Reference no: EM132394077

CDS 230

Assignment

1 Question

Create a vector of 10,000,000 random elements using a function from numpy.random. Compute the average of this vector using the old-fashioned, slow, for loop method. Show the code and the answer.

2 Question

Compute the average using a numpy function. Show the code and the result.

3 Question

The time.time() function will return the current time in terms of seconds. It is possible to determine the computational time of a process by capturing the time before and after the execution of the process. Write a Python script to compute the for the previous two problems. Do not get a new vector, and do not include the creation of the random vector in your timing.

Compute the ratio of the time to compute the average using Problem 1 to the time it took to compute the answer using the method in Problem 2. Show your codes, the times for each method, and the ratio..

4 Question

Use the numpy random seed value of 23423. Create three random vectors, each of length 5. These are named a, b, and c. Compute d = a + b × c. Show your code and all four vectors.

5 Question

Create a 5 × 5 matrix of random values. Use the seed of 453. Using the random slicing technique, write a Python command that retrieves values for the following locations in the matrix (1,3), (2,2), (3,1).

6 Question

Recall the equation used for an object falling under the influence of gravity,

y2 = y1 + v1t + 1/2 gt2.

Start with a height of 600 m. Your task is to compute the height of the object for ten different experiments.

The experiments differ in the amount of time the object drops: t = (1 sec, 2 sec, 3 sec, 4 sec, 5 sec, 6 sec, 7 sec, 8 sec, 9 sec, 10 sec.

To compute the y2 values for all experiments, use,
y 2 = y 1 +1/2gt→ 2.

Once the data variables are assigned, this computation can be done in one line of Python. Show your code and the results.

7 Question

Recall the chaos equation:

xn+1 = rxn(1 - xn).

Python does not offer tools to solve this equation efficiently because it is a recursive equation. The answer to xn is needed before xn+1 can be computed. However, it is possible to use NumPy tools to efficiently calculate the results for several trials using different values of r.

Create a vector rvec which has the values (2, 2.3, 2.8, 3, 3.3,, 4.0). Create a matrix mat which is 50 × 6.

In a single command set the values of the top row of the matrix to 0.1. (This was the initial starting value of x.) Each row in this matrix will be one iteration of the equation and each column is one trial. Create a for loop that spans the number of iterations (49). Inside the for loop there should be a single line that calculates the values for all trials in a single row.

The first values in the first column correspond to the experiment when r = 2.0. The x value in this trial stabilizes at 0.5. Thus, the last four values in the first column should be 0.5. In a single Python command, print out the last for rows for all columns. These values should match the results from the lecture.

8 Question

Consider the case in which the goal is to find a vector ~h such that,
h · xi= 1.

The xi represents a vector from a set of vectors. The equations states that the dot product of the vector h with any of the x vectors is 1.0. The task of this assignment is to find h for a given set of x vectors.

The solution starts with creating a matrix X in which each of the columns is one of the x vectors. The code for generating this matrix is:

1 np . random . seed ( 235 )

2 X = np . random . ranf ((10 ,3) )

The equation to find h is

h = X (XT X)-1c.

The XT is the transpose, and the superscript -1 is the inverse. The c = (1, 1, 1). The length of c is the same as the number of vectors used to make X.

Write a Python script to compute h. Show your codes and results. Confirm your results by compute h · xi where xi is a column from X.

There are three columns in X, so you should confirm the h for each column.

Reference no: EM132394077

Questions Cloud

Definition of operational excellence from peer review : Give a definition of Operational Excellence from a peer review journal. Why are you taking this course and what do you want to get out of the course.
Self-reported gun ownership : According to a Gallup poll about gun ownership, in the year 2016, 270 out of 600 (45%) U.S. households answered "yes" to the question:
What would be your response to shareholders and customers : After watching the required video "Profit's not always the point" by Harish Manwani and reading the article "Samsung delays launch of Galaxy Fold After Screen.
Distribution of students by the academic class : Question 1: The following table summarizes the distribution of students by the academic class in a class.
Compute the average using a numpy function : Create a vector of 10,000,000 random elements using a function from numpy.random. Compute the average of this vector using the old-fashioned.
Is representative of the typical family budget in midwest : What would be the comparable rent in 1990 (CPI 130.7)? Round your answer to the nearest cent (i.e. two decimal places).
How does your selected health profile compare : Analyze Dallas, tx health department's website (e.g., dhhs.gov). A Google search of your city's "health profile" may also yield results. What new information.
Discussion of virtual machines related to forensics analysis : Go to the Forensic Focus website to read the article titled "Virtual Forensics: A Discussion of Virtual Machines Related to Forensics Analysis,"
Should the united states rely on market forces : Write at least a 200 word posting in which you answer the following question and explain your answer. Should the United States rely on market forces to adjust.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd