Describe similarities and differences between numpy

Assignment Help Business Management
Reference no: EM132203061

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

Questions Cloud

What is your perspective on behavioral bias : What is your perspective on behavioral bias? Discuss an economic decision you have made based on behavioral bias rather than rational decision-making.
Comparative advantage in the production of specific items : You are getting ready to open The Shoe Hut, but you need to need to determine whether you have the absolute or comparative advantage in the production
Stores data in hexadecimal format : The RAM of the a computer stores data in Hexadecimal format. Is this correct?
Describe similarities and differences between numpy : Describe similarities and differences between NumPy two-dimensional arrays and matrices. Explain why the code behaves differently for the two.
Describe similarities and differences between numpy : Describe similarities and differences between NumPy two-dimensional arrays and matrices. Explain why the code behaves differently for the two.
Which functional dependency causes bcnf violation : List candidate key(s), and how you found the key(s). Which functional dependency causes BCNF violation? Decompose T1 into BCNF tables. Please show all work he
Briefly discuss the needs for virtual memory : Topic 1: Briefly discuss the needs for virtual memory. Topic 2: Briefly discuss how virtual memory works.
Main objective of cloud computing : What is the main objective of Cloud Computing?
Difference between a microcontroller or microprocessor : What is the primary difference between a microcontroller or microprocessor, and an FPGA?

Reviews

Write a Review

Business Management Questions & Answers

  Measuring total output and national welfare

What are the limitations of the GDP in measuring total output and national welfare?

  Estimate the parameters of the cobb-douglas production

Assume that, for a country called Magnesia, you are trying to estimate the parameters of the Cobb-Douglas production function expressed as follows:

  Fit with the job specifically or the organization

Question 1 - In your opinion, is an employee's fit with the job specifically or the organization overall more important? Explain. (Assume that the employee must have the basic qualifications for the job in order to be hired.)

  Security plan-what employees need to know

After the SAP has been designed, it is time to develop all the supporting materials needed for a successful execution of the plan. During the development phase, it is not only essential to take a close look at the list of identified security topic..

  How can the government be your risk management friend

If you've not noticed this yet, our textbook is terribly British in its orientation and outlook on life; this is clearly apparent in the very brief discussions about legal and regulatory compliance regimes that organizations must deal with.

  Implementing controls for global operationscontrol systems

implementing controls for global operationscontrol systems for global operations fall under direct coordinating

  Circle of trustin the 80s mcdonalds conducted a study to

circle of trustin the 80s mcdonalds conducted a study to determine what motivated its employees to steal. their studies

  Consumers to focus more on health

Both of these companies want their consumers to focus more on their health. HeartJuice has created a beverage with specific ingredients that are beneficial

  Explain how do you determine if the conclusions of empirical

Explain How do you determine if the conclusions of empirical research are logically supported or not?

  Determine genotypic and allelic frequency

How do you determine genotypic and allelic frequency if you are not sure that the hardy-Weinberg condition apply?

  What is the algebraic expression of the given budget

Suppose a cup of coffee at the campus coffee shop is $2.50 and a cup of hot tea is $1.25. Suppose a student's beverage budget is $20 per week. What is the algebraic expression of the budget?

  Define how the role of advocacy impacts healthcare policy

Define how the role of advocacy impacts healthcare policy. Explain how the role of advocacy is consistent with responsibility of the advanced registered nurse.

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