Python code segment

Assignment Help Business Management
Reference no: EM132207653

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: EM132207653

Questions Cloud

Doubling the rate of depreciation : Suppose an increase in air pollution causes capital to wear out more rapidly, doubling the rate of depreciation. How would this affect economic growth
Display the contents of the file on the screen : Write a program that asks the user for the name of a file. The program should display the contents of the file on the screen.
What would you predict for the given variables : The amount of education the typical receives varies substantially among c Suppose you were to compare a coun highly educated labor force and a coun a less.
Write a program that asks the user to enter the size : Write a program that asks the user to enter the size for an array (greater than 0) and fills the array with a set of random numbers between 1 and the number.
Python code segment : Arrays and copy semantics Consider the following Python code segment, which uses built-in Python lists and NumPy lists to perform similar operations
Allstate have to show in order to remove to federal court : What would Allstate have to show in order to remove to federal court?
Descibe three types of strategic trade polices : Explain Paul Krugman's Nwe trade Theroy using a national industry example. The insight of this theory have been used to justify 'strategic trade policy'.
What characteristics of emergency management : What characteristics of emergency management in the United States hinder preparedness efforts?
Write a program that asks the user about his name : Write a program that asks the user about his/her name (you need to take the first name and family name as ONE string).

Reviews

Write a Review

Business Management Questions & Answers

  What is so dangerous about e-waste

What is e-waste? What is so dangerous about e-waste? Many well-meaning individuals thought that recycling was the answer to the e-waste problem.

  Represent in the foreign exchange market

Explain what S and D represent in the foreign exchange market. As the D for dollars increases, what happens to the value of the dollar.

  Find average time a customer spends in queue

Consumers arrive at Homestake Bank between the hours of 10am and 11am according to a Poisson distribution at a mean rate of forty per hour.

  Current replacement cost of a damaged

If claims need to be settled based on the current replacement cost of a damaged or lost item less depreciation, then the _____ method should be used

  Why is it important to back up the dhcp database

Why is it important to back up the DHCP database and Identify key files that make up the DHCP database?

  Walmart is planning to introduce self-scanning robots

Walmart is planning to introduce self-scanning robots. How does this support CRM initiatives? What are the challenges of using this technology?

  Research methodology assignment

The primary purpose of this Research Methodology Assignment is to give you experience in determining appropriate research methods to be used with the research question and hypotheses you have posed and with the type data you would need to collect ..

  Explain how might such exchanges make your work faster

Illustrate what are these applications and explain why was such an exchange desirable? Explain how might such exchanges make your work faster, more efficient or more accurate?

  Strategies not compatible with rapid development

Why are other strategies not compatible with rapid development? Explain

  Large and small manufacturing firms

In other words, though JIT was originally designed for large manufacturing firms it is applicable to both large and small manufacturing firms.

  Explain the three internal governance mechanisms

Analyze the three internal governance mechanisms and recommend a possible fourth mechanism that would help align the interests of managerial agents with those of the firm's owners.

  Best way for the health care provider to distinguish

From the e-Activity, determine the best way for the health care provider to distinguish its product offerings from those of its competitors. Provide specific examples to support your response.

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