PYTHON

Attached below

CSCI333.01W Assignment 09

Don't use plagiarized sources. Get Your Custom Essay on
PYTHON
Just from $13/Page
Order Essay

Array-Oriented Programming with NumPy

100 points

Deadline: 3/30/

2

020 Tue. by 11:59pm

1. (20 points, each 2 points) True or False questions:

1) (True/False) The NumPy library provides the ndarray data structure (synonym “array”), which is typically much faster than Python lists.

Answer:

2) (True/False) Function array() creates an array from an array or other iterables.

Answer:

3)(True/False) NumPy array can contain different data types in one array.

Answer:

4) (True/False) When one of the operands of an array operator is a scalar, NumPy uses broadcasting to perform the calculation as if the scalar were an array of the same shape as the other operand, containing the scalar value in all its elements.

Answer:

5) (True/False) The array method copy() returns a new array that is a view (shallow copy of the original array.

Answer:

6) (True/False) NumPy ravel() function flattens arrays to 1D and returns view/shallow copy of the original array.

Answer:

7) (True/False) When using reshape() function to change the shape of an array, the new shape does not have to have the same number of elements as the original array.

Answer:

8) (True/False) Compare to Python lists, NumPy array is faster, occupies less memory, and more convenient to use.

Answer:

9) (True/False) The dimension of arrays cannot be changed.

Answer:

10) (True/False) NumPy array elements can be iterated using a for loop.

Answer:

2. (20 points) Multiple choice or Fill in blank questions:

1) (6 points) arr1 = numpy.array([[1,2,3],[4,5,6]]), which of the following create(s) a deep copy, which create(s) a view(shallow) copy, which do(es) not create a copy (has the same id() with the original), list the following a) – f) cases to the corresponding category:

a) arr2 = arr1

b) arr2 = arr1.copy()

c) arr2 = arr1.view()

d) arr2 = arr1.flatten()

e) arr2 = arr1.ravel()

f) arr2 = arr1.T

Answer:

Deep copy:

View (Shallow) copy:

No copy:

2) (2 points) Assume arr = numpy.array([[1,1,5], [2,5,8], [4,12,25], [13,27,30]]), what is the result for print(arr.shape)?

a) (4, 3)

b) (3, 4)

c) (2, 3)

d) (3, 2)

Answer:

3) (2 Points) The position indexes of the elements in NumPy arrays starts with ___

a) 1

b) 0

Answer:

4) (3 points) Assume arr = numpy.array([[1,1,5], [2,5,8], [4,12,25], [13,27,30]]), you want to replace the value 12 to 100, please write statement(s) to change the value:

Answer:

5) (3 points) Assume arr = numpy.array([1,2,3,4,5,6,7,8]), we want to change the dimension of the arr to (2, 2, 2), write statement(s) to change it:

Answer:

6) (4 points) Write statements to create and output 10 evenly spaced numbers for x in 2 by 5 array: 0<= x <= 1

Answer:

3. (25 points) Hand-trace the following code. What is the output, or what error/problem do you observe and why?

1) (5 points)

# create a 2D array from existing data

import numpy as np
arr=np.array([[2, 4, 6, 8], [1, 3, 5, 7]])
print(arr)

Output:

2) (5 points)

Output:

#Display the number of dimensions and shape of the array

import numpy as np
arr=np.array([[2, 4, 6, 8, 10], [1, 3, 5, 7, 9]])
print(arr.ndim)
print(arr.shape)

3) (5 points)

Output:

#Create a 1D array from a list comprehension that produces even integers from 2 through 20

import numpy as np
arr = np.array([x for x in range(2, 21, 2)])
print(arr)

4) (5 points)

Output:

#use function arange() to create a 1D array and reshape it into a 2D 3-by-4 array

import numpy as np
arr = np.arange(1, 13).reshape(3, 4)
print(arr)

5) (5 points)

Output:

# create an array of the values from 1 through 5, then use broadcasting to square each value:

import numpy as np
arr = np.arange(1, 6) ** 2
print(arr)

4. (20 points) Write a program to create an array containing the values 1-15, reshape it into a 3-by-5 array (3 rows, 5 columns), then use indexing and slicing techniques to perform each of the following operations, and print each selection:

a) Select row 0

b) Select column 4

c) Select rows 0 and 1

d) Select columns 2-4

e) Select the element that is in row 1 and column 4

f) Select all elements from rows 1 and 2 that are in columns 0, 2, and 4

(Hint: Rows and Columns of NumPy array start from 0)

Answers:

(18 points, for each sub-question, 2 points for code, 1 point for result)

Write your program here, or copy/paste a screenshot of your Program, as well as your output results:

(2 points) Save the program as “program1.py”. Upload the .py file as part of your submission.

5. (15 points) Write a program,

1) use numpy arange() and reshape() to create, and print the following array:

array([[ 1, 2, 3],

[ 4, 5, 6]])

2) use numpy hstack(), vstack() to create, and print the following array:

array([[ 1, 2, 3, 1, 2, 3],

[ 4, 5, 6, 4, 5, 6],

[ 1, 2, 3, 1, 2, 3],

[ 4, 5, 6, 4, 5, 6]])

3) Multiply the resulting array from step 2) by itself. Print the array.

4) Concatenate resulting arrays from step 2) and step 3), axis = 0. Print the array.

Answers:

(10 points) Write your program here, or copy/paste a screenshot of your Program:

(3 points) Screenshot of the outputs:

(2 points) Save the program as “program2.py”. Upload the .py file as part of your submission.

6. (20 points)

1) (10 points) Write a program to create a 3 by 3 array containing the even numbers from 2 through 18. Create a second 3 by 3 array containing integers from 9 down to 1, then multiply the first array by the second. Show the result.

2) (10 Points) Write a program to create a 2 by 3 array (assume 2 by 3 array name is arr), it contains values of the first six powers of 2, like . Flatten arr array first with method flatten(), then flatten arr with ravel(). In each case, display the resulting arrays then display the original arr array to show that the original array’s shape was unmodified by flatten() or ravel().

(hint: To create the values of the array, one way is to use numpy.arange() to create an array, then use numpy power function to get the “2 to the power of” each array element. Search and review this link (

https://docs.scipy.org/doc/numpy/reference/generated/numpy.power.html

) learn how to use numpy power function)

Answers for 1)

(6 points) Write your program here, or copy/paste a screenshot of your Program:

(2 points) Output result:

(2 point) Save the program as “bonus1.py”. Upload the .py file as part of your submission.

Answers for 2)

(6 points) Write your program here, or copy/paste a screenshot of your Program:

(2 points) Output result:

(2 points) Save the program as “bonus2.py”. Upload the .py file as part of your submission

2

What Will You Get?

We provide professional writing services to help you score straight A’s by submitting custom written assignments that mirror your guidelines.

Premium Quality

Get result-oriented writing and never worry about grades anymore. We follow the highest quality standards to make sure that you get perfect assignments.

Experienced Writers

Our writers have experience in dealing with papers of every educational level. You can surely rely on the expertise of our qualified professionals.

On-Time Delivery

Your deadline is our threshold for success and we take it very seriously. We make sure you receive your papers before your predefined time.

24/7 Customer Support

Someone from our customer support team is always here to respond to your questions. So, hit us up if you have got any ambiguity or concern.

Complete Confidentiality

Sit back and relax while we help you out with writing your papers. We have an ultimate policy for keeping your personal and order-related details a secret.

Authentic Sources

We assure you that your document will be thoroughly checked for plagiarism and grammatical errors as we use highly authentic and licit sources.

Moneyback Guarantee

Still reluctant about placing an order? Our 100% Moneyback Guarantee backs you up on rare occasions where you aren’t satisfied with the writing.

Order Tracking

You don’t have to wait for an update for hours; you can track the progress of your order any time you want. We share the status after each step.

image

Areas of Expertise

Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.

Areas of Expertise

Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.

image

Trusted Partner of 9650+ Students for Writing

From brainstorming your paper's outline to perfecting its grammar, we perform every step carefully to make your paper worthy of A grade.

Preferred Writer

Hire your preferred writer anytime. Simply specify if you want your preferred expert to write your paper and we’ll make that happen.

Grammar Check Report

Get an elaborate and authentic grammar check report with your work to have the grammar goodness sealed in your document.

One Page Summary

You can purchase this feature if you want our writers to sum up your paper in the form of a concise and well-articulated summary.

Plagiarism Report

You don’t have to worry about plagiarism anymore. Get a plagiarism report to certify the uniqueness of your work.

Free Features $66FREE

  • Most Qualified Writer $10FREE
  • Plagiarism Scan Report $10FREE
  • Unlimited Revisions $08FREE
  • Paper Formatting $05FREE
  • Cover Page $05FREE
  • Referencing & Bibliography $10FREE
  • Dedicated User Area $08FREE
  • 24/7 Order Tracking $05FREE
  • Periodic Email Alerts $05FREE
image

Our Services

Join us for the best experience while seeking writing assistance in your college life. A good grade is all you need to boost up your academic excellence and we are all about it.

  • On-time Delivery
  • 24/7 Order Tracking
  • Access to Authentic Sources
Academic Writing

We create perfect papers according to the guidelines.

Professional Editing

We seamlessly edit out errors from your papers.

Thorough Proofreading

We thoroughly read your final draft to identify errors.

image

Delegate Your Challenging Writing Tasks to Experienced Professionals

Work with ultimate peace of mind because we ensure that your academic work is our responsibility and your grades are a top concern for us!

Check Out Our Sample Work

Dedication. Quality. Commitment. Punctuality

Categories
All samples
Essay (any type)
Essay (any type)
The Value of a Nursing Degree
Undergrad. (yrs 3-4)
Nursing
2
View this sample

It May Not Be Much, but It’s Honest Work!

Here is what we have achieved so far. These numbers are evidence that we go the extra mile to make your college journey successful.

0+

Happy Clients

0+

Words Written This Week

0+

Ongoing Orders

0%

Customer Satisfaction Rate
image

Process as Fine as Brewed Coffee

We have the most intuitive and minimalistic process so that you can easily place an order. Just follow a few steps to unlock success.

See How We Helped 9000+ Students Achieve Success

image

We Analyze Your Problem and Offer Customized Writing

We understand your guidelines first before delivering any writing service. You can discuss your writing needs and we will have them evaluated by our dedicated team.

  • Clear elicitation of your requirements.
  • Customized writing as per your needs.

We Mirror Your Guidelines to Deliver Quality Services

We write your papers in a standardized way. We complete your work in such a way that it turns out to be a perfect description of your guidelines.

  • Proactive analysis of your writing.
  • Active communication to understand requirements.
image
image

We Handle Your Writing Tasks to Ensure Excellent Grades

We promise you excellent grades and academic excellence that you always longed for. Our writers stay in touch with you via email.

  • Thorough research and analysis for every order.
  • Deliverance of reliable writing service to improve your grades.
Place an Order Start Chat Now
image

Order your essay today and save 30% with the discount code Happy