Arrays and copy semantics

Assignment Help Business Management
Reference no: EM132194565

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

Questions Cloud

Marketing strategy for the chosen organization : UCBS7038 - Marketing Management - describe and critique its Marketing.To choose the case study, pick a company, or even a not-for-profit organization
What are the truth values : Suppose that Q(x) is the statement "x + 2 = 4x." What are the truth values of the following statements? Assume x is representing all real numbers.
By what factor must the work done on the object be : A net force acts on an object and accelerates it from rest to a speed V1. In doing so, the force does an amount of work W1. By what factor must be the work done
What exploratory research should edward jones do : Many people in minority groups, including African Americans, Hispanic Americans, Asian Americans, and Native Americans, do not invest.
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 is the energy density : A capacitor is formed from two concentric spherical conducting shells separated by vacuum. The inner sphere has radius 11.0 cm, and the outer sphere has radius.
What is an optimal huffman code : What is an optimal Huffman code for the following set of symbols with associated frequencies? a:13, b:7, c:2, d:9, e:5, f:8, g:3, h:11
Allow the user to enter the size of the matrix such as n : Write a C++ program that Allow the user to enter the size of the matrix such as N.
Which functional dependency causes bcnf violation : List candidate key(s), and how you found the key(s). Which functional dependency causes BCNF violation?

Reviews

Write a Review

Business Management Questions & Answers

  Carrot-and-stick approach to motivation

Consider a time when you received a reward similar to the carrot-and-stick approach to motivation.

  Captures the essence of the major lessons

Create a metaphor or analogy that captures the essence of the major lessons

  Prepare a scope statement for the transition project

Prepare a scope statement for the transition project. Identify the most logical project sponsor and justify your choice with at least two supporting reasons.

  Explain the impact of organizational culture and structure

Explain impact of organizational culture and structure on that opportunity for strategic change. Formulate conclusions including personal learning on analysis.

  Crowdfunding-the new mother of angel investors

What are the pros and cons of crowdfunding? Look at it first from the perspective of the entrepreneur who needs the money Look at it also from the side.

  Reputation as a great place to work

How concerned one should be about an organization's "brand" and reputation as a great place to work?

  Analysis and presentation of forensic information

Describe the analysis and presentation of forensic information. Based on your training, you know you will need to include file system analysis

  Problems expanding to culture with 50 under 15 yrs oldneed

problems expanding to culture with 50 under 15 yrs oldneed to have ideas and references on what type of problems to

  Presume you attend a meeting at work

Presume you attend a meeting at work to deliberate whether to change the price of your product. You think demand is elastic however a colleague thinks it is inelastic.

  Acting in the shareholders best interests

Your company's management immediately begins fighting off this hostile bid. Is management acting in the shareholders' best interests? Why or why not.

  Interdependence that operations finance and marketing

Compare and contrast an existing organization's three major functions (i.e., finance, marketing, and operations), and then justify the interdependence that operations have to finance and marketing. Provide examples to support your rationale.

  Please choose an indigenous group-past or present

Please choose an indigenous group, past or present. There is a long list of such groups here: https://en.wikipedia.org/wiki/List_of_indigenous_peoples.

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