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

  Common tools for dealing with each problem

Which do you think poses greater problems for a network support specialist: the extensive cables required in a wired network or the security problems

  Identify some of the employment law

Identify some of the employment law issues discussed in the Presidential election cycle. In your opinion, what is the most important? Why? Chose at least one news article or academic article to support your opinion or illustrate your discussion.

  Linear and integer programming modeling

The paper must (a) identify the main issues in the chosen area, (b) apply and reference new learning to the chosen area, (c) build upon class activities or incidents that facilitated learning and understanding, and (d) present specific current and..

  Presents the strategic planning process

Overview of strategic management: The NetMBA site (see assignments) presents the strategic planning process schematically as follows: Mission -- Objectives -- Situation -- Analysis -- Strategy Formulation -- Implementation.

  Proposal to limit the amount of money doctors

Assume that a politician introduces a proposal to limit the amount of money doctors can earn.

  Global ideals and local responses

How can managers adapt to a culturally diverse workforce in the US and globally? How can managers adapt to a demographically diverse workforce (including but not limited to age diversity)? Discuss how or if leadership moderates the effects of cult..

  Aspect of organizing in the context of organizational

Identify and explain the four fundamental issues that pertain to the formal aspect of organizing in the context of organizational structures.

  Program that calculates the total for a purchase

Try a program that calculates the total for a purchase at a wholesale store.

  What are goodwill industries business strategies

What are Goodwill Industries business strategies? Determine a business strategy that would work better if you were a competitor.

  Discuss the principle of exploits

Research and discuss the principle of exploits based on buffer-overflow attacks.

  Discuss making a decision using baye decision rule

Discuss making a decision using Baye's decision rule (probabilities) for "the maximax approach", "the maximin approach", the "maximum likelihood approach" and how it can be used/applied to your personal life and also in professional situations. P..

  Optimal value of the objective function

A publisher has orders for 500 copies of a certain textbook from San Francisco and 600 copies from Sacramento. The publisher has 700 copies in a warehouse

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