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

  Learning in action

Learning contract proposal that will form the basis of your learning contract report.

  Change is the only constant

"Change is the only constant " Evaluate the different types of change that have occurred in Sony.

  How do advertisers try to use group influence

How do advertisers try to use group influence?  Will you find any specific examples and explain the relevant theory of group behavior and influence?

  Case study:saving sony

You have been appointed by Sony as a consultant on change management. Advise Sony on how they could implement the change by using the various theories of change you have learnt.

  How the stock market works

The purpose of this project is to help you to gain an understanding of how the stock market works and of the relationship between theory and practice.

  Find the optimal production quantities

Find not only the optimal production quantities, but also the optimal total cost.

  Describe the management process

Describe the management process and identify the skills required to manage business organizations.

  Case study : bert''s bonsai and aquatic sport museum

Case Study : Bert's Bonsai and Aquatic Sport Museum Prepare a knowledge management system.

  Knowledge management techniques

Demonstrate understanding of the many-sided nature of knowledge management

  Theory of transtheoretical model

Demonstrate understanding of the many-sided nature of knowledge management

  Write a paper on historical trends of management

Write a paper on Historical Trends of Management.

  Theory of reasoned action

Theory of Planned Behavior and Integrated Behaviors Model

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