Arrays and copy semantics

Assignment Help Management Theories
Reference no: EM132191412

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

Questions Cloud

What are the key takeaways : Reflection on what you learned from success and how it help you in your life and your school .
Review problem related to course conclusion : You have just completed 10 weeks of a computer and interaction design course. Imagine you have been asked to create a one-day training course highlighting.
Different personal-positional power types within leadership : In reference to the different personal and positional power types within leadership; Is expert power the best? Why or why not?
How will you manage these challenges in order to achieve : Which goal or goals do you think will be your greatest challenge? Why? How will you manage these challenges in order to achieve your goals?
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.
What you have just learned within the past weeks : You have just completed ten (10) weeks of a mobile programming course. Imagine you have been asked to create a one-day training course that highlights.
Describe a time in your life in which you were engaged : Describe a time in your life in which you were engaged in a situation with someone of a different culture and how those differences complemented.
Which functional dependency causes bcnf violation : List candidate key(s), and how you found the key(s). Which functional dependency causes BCNF violation?
Create a policy and processes document for computer lab : You have been hired to perform computer investigations and forensics analysis for a company. You find that no policies, processes, or procedures are currently.

Reviews

Write a Review

Management Theories Questions & Answers

  Find a cost-minimizing production plan

A firm manufactures two products. Their production capacities for the two products, unit production costs, and estimated demands are shown in Table.

  Examined the ways we use research to help solve problems

This week, through our work, we have examined the ways we use research to help solve problems, how we choose topics to write about, and how we use the work of others to help support our ideas

  Which management approach use to run organization

Which management approach (for example, Theory X or Y) do you propose to use to run your organization? In 50 or fewer words write a statement describing.

  The various privileges to defamation suits

Explain the application of the various privileges to defamation suits and how they are affected by whether the plaintiff is (a) a public figure, (b) a public official, or (c) a private person.

  The participant

The participant will be expected to follow the nursing process to assess, diagnose, plan implement and evaluate the care of a case managed client.

  Que está evaluando el potencial de expansión

CHB, Inc., es una compañía bancaria que está evaluando el potencial de expansión en una región de 13 condados en la parte suroeste del estado. La ley estatal permite establecer sucursales en cualquier condado que se encuentra junto a un condado en..

  Calculate mad

Consider the following sample data: Calculate the range. Calculate MAD. Calculate the sample variance.

  Problem on management control systems and innovation

Management Control Systems and Innovation The president of a fast-growing, high-technology firm remarked, "Developing budgets and comparing performance.

  Briefly describe how ifrs guidelines for recognizing revenue

Briefly describe how IFRS guidelines for recognizing revenue from multiple-deliverable arrangements differ from U.S. GAAP guidelines.

  An article research regarding the atc system

Visit the Hunt Library and conduct an article research regarding the ATC system. Select a topic on safety, organization, or an aspect of technology and modernization.Summarize the article, explain and correlate the relevancy of the article to the mod..

  Should student loan discharged through filing for bankruptcy

Woodcock graduated from law school and fi nished his MBA in 1983. His student loans came due nine months later. Because he was a part-time student until 1990.

  Implied powers in making public policy

Based on the American "constitution," which internal and external stakeholders, in the policy making process, possess "constitutional legitimacy" for their role in making public policy? Do entities with explicit power have more influence than those e..

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