[go: up one dir, main page]

0% found this document useful (0 votes)
17 views3 pages

Digital Data Part 5

This document provides an overview of the NumPy library, its capabilities, and how to create and manipulate ndarray objects. It covers the creation of arrays, various mathematical and linear algebra operations, and the benefits of using NumPy over traditional lists. Additionally, it includes practice questions to reinforce understanding of the concepts presented.

Uploaded by

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

Digital Data Part 5

This document provides an overview of the NumPy library, its capabilities, and how to create and manipulate ndarray objects. It covers the creation of arrays, various mathematical and linear algebra operations, and the benefits of using NumPy over traditional lists. Additionally, it includes practice questions to reinforce understanding of the concepts presented.

Uploaded by

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

DATA SCIENCE PART 4

Learning objectives
By the end of this section you should be able to

Describe the NumPy library.


Create a NumPy array object.
Choose appropriate NumPy functions to process arrays of numerical data.
NumPy library
NumPy (Numerical Python) is a Python library that provides support for efficient
numerical operations on large, multi-dimensional arrays and serves as a
fundamental building block for data analysis in Python. The conventional alias for
importing NumPy is np. In other words, NumPy is imported as import numpy as
np. NumPy implements the ndarray object, which allows the creation of a multi-
dimensional array of homogeneous data types (columns with the same data
type) and efficient data processing. An ndarray object can have any number of
dimensions and can store elements of various numeric data types. To create a
NumPy ndarray object, one of the following options can be used:

Creating an ndarray by converting a Python list or tuple using the np.array()


function.
Using built-in functions like np.zeros() and np.ones() for creating an array of all
0's or all 1's, respectively.
Generating an array with random numbers using np.random.rand(n, m), where n
and m are the number of rows and columns, respectively.
Loading data from a file. Ex: np.genfromtxt('data.csv', delimiter=',').

Concepts in Practice
NumPy library

Which of the following creates an ndarray object with one row and two columns?
a. np.array([2, 3])
b. np.zeros(1, 2)
c. np.zeros((1, 2))

Which of the following is a NumPy data type?


a. ndarray
b. list

1|Page
DATA SCIENCE PART 4

c. array

What is the benefit of using anndarray object compared to a list?


a. computational efficiency
b. array-oriented computing
c. memory efficiency
d. all the above
NumPy operations
In addition to the ndarray data type, NumPy's operations provide optimized
performance for large-scale computation. The key features of NumPy include:
 Mathematical operations: NumPy provides a range of mathematical
functions and operations that can be applied to entire arrays or specific
elements. These operations include arithmetic, trigonometric, exponential,
and logarithmic functions.
 Array manipulation: NumPy provides various functions to manipulate the
shape, size, and structure of arrays. These include reshaping, transposing,
concatenating, splitting, and adding or removing elements from arrays.
 Linear algebra operations: NumPy offers a set of linear algebra functions
for matrix operations, like matrix multiplication, matrix inversion,
eigenvalues, and eigenvectors.
Concepts in Practice
NumPy operations

What is the output of the following code?


import numpy as np

arr = np.array([[1, 2], [3, 4]])


out = 2 * arr
print(out)
a. [[2 4]
b. [8 16]]
c. [[2 4]
d. [6 8]]
e. [[1 2]
f. [3 4]]

2|Page
DATA SCIENCE PART 4

Which of the following results in a 2 by 3 ndarray?


a. import numpy as np
b. arr = np.array(2, 3)
c.
d. import numpy as np
e. arr = np.array([[1, 2], [1, 2], [1, 2]])
f.
g. import numpy as np
h. arr = np.array([[1, 2], [1, 2], [1, 2]]).T
i.

The function np.multiply(arr1, arr2) receives


two ndarray objects arr1 and arr2 with the same dimensions, and performs
element-wise multiplication. What is the output of the following code?
import numpy as np

arr1 = np.array([[1, 2], [3, 4]])


arr2 = np.array([[1, 0], [0, 1]])
out = np.multiply(arr1, arr2)
print(out)
a. [[1 0]
b. [0 4]]
c.
d. [[1 2]
e. [3 4]]
f.
g. [[2 2]
h. [3 5]]
Exploring further
Please refer to the NumPy user guide for more information about the NumPy
library.

3|Page

You might also like