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

  Returning from the internet web servers

Also write a named extended ACL called BROWSING that has to be created to let traffic returning from the Internet web servers back in.

  Inappropriate while representing livingsocial escapes

Maya needs to be realistic about the improper conduct that can occur on a weekend trip and set clear and explicit guidelines for the consequences.

  Research design and statistical information

How do research design and statistical information affect validity?

  Critically analyze the toyota''s mission and vision

Critically analyze the toyota's mission and vision.

  The importance of goal setting

Provide one (1) specific scenario of an employee using goal-setting to increase work motivation and task performance, reduce stress, and improve the accuracy of performance evaluation.

  Payment in kind program

In 1983 the Reagan Administration launched a new agricultural event called the Payment-in-Kind (PIK) program. Keeping this event in mind suppose that free market price of wheat is $4 per bushel.

  Identity of likely outsourced manufacturing company

Identity of likely outsourced manufacturing company, if you have a product-based company and/or will outsource development of a technology product/service.

  Definition on nursing informatics was technology

The definition has evolved to include the central focus on the concepts of data, information, and knowledge. How do you feel the new definition

  Do you think these attributes are critical for successful

Do you think these attributes are critical for successful leadership? Why or why not?

  Find gini index of income concentration for lorenz curve

Find the Gini index of income concentration for each Lorenz curve. Will the proposed changes provide a more equitable income distribution? Explain.

  Role of policy analysis in policy modification

1. Discuss the role of policy analysis in policy modification. 2. Include brief descriptions of three federal agencies that support policymaking through policy analysis.

  Know the difference between single double loop learning

1. Know the difference between single double loop learning?

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