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 pep program that inputs the scores

Write a Pep/9 program that inputs the scores and outputs a message indicating whether the students passed. Note that it is not necessary to use arrays.

  Display all us states in alphabetical order

Display all U.S. States in Alphabetical order along with Capital and Flower. Search for a specific state and display the appropriate Capital and Bird.

  How does one define a new class and its methods

What is meant by the methods associated with a class/object? How do they relate to object-oriented programming? How does one define a new class and its methods?

  Prepare a complete flow chart for the project

Implementing the design using principles of correct syntax, layout, and program structure - Prepare a Complete Flow Chart for the Project - Write the code

  Focus on applying one data analytic algorithm

SIT742 Modern Data Science - you need to collect data from the internet by yourselves. For example, you can download from open data sites or gather

  Write the function that draws car image with turtle graphics

Write the function draw_car that draws, with Turtle graphics, the car from the image that you can find at the end of the homework.

  Write a progra m that creates two objects

Write a progra m that creates two objects, object of the ProductionWorker class and an object of ShiftSupervisor r class.

  Write a program that will generate a random recycle bin

Write a program that will generate a random recycle bin. This program will have a menu that allows the user to generate a new recycle bin.

  Design a python program that prompts the user to enter

Design a PYTHON program that prompts the user to enter a number and then you will build a multiplication table of that size.

  Calculate the amount of money a person would earn

Write a program that calculates the amount of money a person would earn over a period of time if their salary is one penny the first day, two pennies.

  Design a python program to analyze weather data

Design a Python program to analyze weather data. Ask the user to enter the daily high temperature of 5 days. Store the termeratures in a list.

  Explain the differences between a variable and data types

Explain the differences between a variable and data types. What other source did you find that helped you improve your understanding of Python Programming.

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