Built-in python lists and numpy lists

Assignment Help Basic Computer Science
Reference no: EM132193807

Part A) Arrays and copy semantics Consider the following Python code segment, which uses built-in Python lists and NumPy lists to perform similar operations, albeit with differing results.

Using built-in Python lists:

>>> data = [1, 2, 3, 4]

>>> print data [1, 2, 3, 4]

>>> otherData = data

>>> otherData[1] = -2

>>> print otherData [1, -2, 3, 4]

>>> print data [1, -2, 3, 4]

>>>

>>> otherData = data[1:3]

>>> print otherData [-2, 3]

>>> otherData[0] = 0

>>> print otherData [0, 3]

>>> print data Using NumPy arrays:

>>> import numpy as np

>>> data = np.array([1, 2, 3, 4])

>>> print data [1 2 3 4]

>>> otherData = data

>>> otherData[1] = -2

>>> print otherData [1 -2 3 4]

>>> print data [1 -2 3 4]

>>>

>>> otherData = data[1:3]

>>> print otherData [-2 3]

>>> otherData[0] = 0

>>> print otherData [0 3]

>>> print data [1 0 3 4]

Describe similarities and differences between copying and assignment semantics of built-in Python lists and NumPy arrays. Explain why the code behaves differently for the two.

Part B) Matrices NumPy also supports matrices. However, there are some important differences between two-dimensional arrays and matrices. Consider the following two code segments that are similar, but produce different results: Using NumPy two-dimensional arrays:

>>> A = np.array([[1,2], [3,4]])

>>> B = np.array([[2,1], [-1,2]])

>>> A * B array([[ 2, 2], [-3, 8]])

>>> A ** 3 array([[ 1, 8], [27, 64]])

Using NumPy matrices:

>>> A = np.matrix([[1,2], [3,4]])

>>> B = np.matrix([[2,1], [-1,2]])

>>> A * B matrix([[ 0, 5], [ 2, 11]])

>>> A**3 matrix([[ 37, 54], [ 81, 118]])

Describe similarities and differences between NumPy two-dimensional arrays and matrices. Explain why the code behaves differently for the two.

Reference no: EM132193807

Questions Cloud

Modifying it to become a nested loop : Make this into a one-second delay loop, by modifying it to become a nested loop.
Sales transactions of the department store : What kind of business rules could be used for sales transactions of the department store.
Characters that not in the range : Given a text consists of words, letters, numbers, punctuations, and whitespaces. Filter out any characters that not in the range of '0'..'9', 'a'..'z' or 'A'..'
Built-in python lists and numpy lists : Consider the following Python code segment, which uses built-in Python lists and NumPy lists to perform similar operations, albeit with differing results
What sort of opportunities do you have : What sort of opportunities do you have, or can you find or create in future, to practice what you are learning in class?
Locations of users in real time : What types of new applications can emerge from knowing locations of users in real time? What if you also knew what they have in their shopping cart, for example
What is the average time to read a single sector : Suppose we have a magnetic disk with the following parameters:
Do you believe recall elections are good for democracies : The new governor Ragnvold A. Nestos did not try to break apart the grain elevator and state bank.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Issues of property ownership in cyberspace

1. What are some issues of property ownership in cyberspace?

  Problem regarding the participant in the project

Begin your response by describing your EAI scenario. Be sure to include your role or perspective on this project. Were you a participant in the project, a consumer of the project's result, or both?

  What is the best estimate of the risk-free rate

Treasury bill expiring on April 20 had a bid discount of 5.86, and an ask discount of 5.80. What is the best estimate of the risk-free rate as given in the text

  Estimate the size and shape of the roof

Construct the building shown in Fig. 15-7 using the PLINE and SOLID commands. Specify a line width of .05 unit. Estimate the size and shape of the roof.

  Fit a poison regression model to relate success

Show that the logistic model gives a better fit than the Poisson regression which the kick is taken. Use Attempts as offset (See Page 347). distance from which the kick is taken. model.

  Assingments from western governors university

Where can I find more examples of a capstone (LQT2) assingments from Western Governors University?

  What is the pulse rate

How many pulses are received by the control system to verify that table has moved exactly 15 cm?

  What are certification and accreditation

What are certification and accreditation when applied to information systems security management? List and describe at least two certification or accreditation processes.

  Basis of international division of labor

What do you think of an idea of comparative advantage as a basis of international division of labor?

  Estimate the required size of an fpga

FPGAs are available in a number of sizes. Given that smaller FPGAs will be cheaper, what criteria would you use to estimate the required size of an FPGA, prior to detailed design?

  What is the volumetric flow rate from the pool

A smooth plastic, 10-m-long garden hose with an inside diameter of 15 mm is used to drain a wading pool as is shown in Fig. P14.28. What is the volumetric flow rate from the pool? Assume KL = 0.8 for the minor loss coefficient at the hose entrance.

  Sections of windows server pro

Complete the following sections of "Windows Server Pro: Install and Configure" in TestOut LabSim®:

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