0% found this document useful (0 votes)
6 views5 pages

Assignment_ Python for Data Analysis - NumPy

Uploaded by

togiyagi258
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Assignment_ Python for Data Analysis - NumPy

Uploaded by

togiyagi258
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Objective:

This assignment will test your understanding of NumPy, including array creation, indexing, selection,

broadcasting, and mathematical operations. Complete each task with the appropriate code and explanations.

(What about the formatting, pdf or colab?)

Part 1: Creating NumPy Arrays

1.​ Using Built-in Methods: Create the following arrays using NumPy built-in functions:

○​ An array of numbers from 0 to 20 with a step of 2.

○​ A 3x3 identity matrix.

○​ A 4x4 array filled with ones.

○​ An array of 10 equally spaced numbers between 5 and 50.

2.​ Creating Arrays from Lists

○​ Convert a Python list [10, 20, 30, 40, 50] into a NumPy array.

○​ Generate a 3x3 matrix of random numbers using rand(), randn(), and randint().

3.Array Attributes

○​ Print the shape, size, and data type of an array you created in the previous steps.
Part 2: Indexing and Selection

1.Basic Indexing and Selection

○​ Create a NumPy array [5, 10, 15, 20, 25, 30]. Select and print:

■​ The first element.

■​ The last three elements.

■​ The elements at index positions 1 to 4.

2. Slicing and Views

○​ Create a 3x3 matrix from np.arange(1, 10).reshape(3, 3) and:

■​ Select the second row.

■​ Select the first two columns.

■​ Extract a sub-matrix of shape (2,2).

3. Broadcasting

○​ Create a 3x3 matrix and add 10 to every element.

○​ Multiply the first column by 2.


4.Copying Arrays

○​ Create a NumPy array and demonstrate the difference between shallow and deep

copies.+

5.Fancy Indexing

○​ Given arr = np.arange(10, 101, 10), select elements at index [0, 3, 5].

Part 3: NumPy Operations

1.​ Mathematical Functions

○​ Find the maximum, minimum, index of max, and index of min for the array [3, 7, 2,

9, 12, 5, 10].

2.​ Universal Array Functions

○​ 1. Given arr = np.array([1, 2, 3, 4, 5]), apply the following functions:

a.​ Square root (sqrt())

b.​ Exponential (exp())

c.​ Sine (sin())

d.​ Logarithm (log())

Submission Instructions:

●​ Save your completed Python script as numpy_assignment.py.

●​ Ensure all code is properly commented.


●​ Submit your work by the deadline.

Evaluation Criteria:

●​ Correctness: The code runs without errors and produces the expected output.

●​ Understanding: Solutions are well-commented and explain the logic behind the code.

●​ Code Readability: Clean and properly formatted code with meaningful variable names.

You might also like