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

  Processes and flow charting in relation to quality

Describe the effect of not considering quality - What is the purpose of processes and flow charting in relation to quality?

  The study at princess alexandra hospital

Refer to the study at Princess Alexandra Hospital (in the "Improvements in Healthcare" section). How do you feel about Google searches finding the correct diagnosis in 57 percent of the cases? Are you impressed with these results? Why or why not? ..

  Explain how the five steps of the organizing process

Explain how the five steps of the organizing process determine the characteristics of the resulting organization. Which steps are most important?

  Monopolist maximizes profit by producing the quantity

A monopolist maximizes profit by producing the quantity at which marginal revenue equals marginal cost.

  Which of given effects are benefits

Which of these effects are benefits? Mo receives the benefits? Which are costs? Who bears the costs? Which are neither costs nor benefits?

  Segments affect the corporation

Choose the two (2) segments of the general environment that would rank highest in their influence on the corporation you chose. Assess how these segments affect the corporation you chose and the industry in which it operates.

  Discuss the interaction between business and management

Discuss the interaction between business and management function in a farming enterprice.

  The relationship between management and labour

Paper on howsocial media affected the relationship between management and labor.

  Choose a criminal event and detail how it might illustrate

choose a criminal event and detail how it might illustrate the conflict model which emphasizes disparity between the

  Describe the fundamental rights

In your lectures this week, beginning of life, fundamental rights, and Roe vs. Wade provided a perspective of ethical issues.

  The market from first planning its entry strategy

To assess the progress made by the organisation in establishing itself in the market from first planning its entry strategy until now.

  Project scheduling assignment - microsoft project

The following questions in the MS Project Scheduling Assignment are to be answered using Microsoft Project. In order to turn in your work from MS Project where required, copy the displays from MS Project into this MS Word document after copying the..

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