Podcast
Questions and Answers
X = np.array([[1,2,3],[4,5,6]])
a = np.array([0,1,0])
What is the output when multiplying the array X by the array a?
X = np.array([[1,2,3],[4,5,6]]) a = np.array([0,1,0]) What is the output when multiplying the array X by the array a?
Broadcasting allows mathematical operations between NumPy arrays of the same shape only.
Broadcasting allows mathematical operations between NumPy arrays of the same shape only.
False
X = np.array([[1,2,3],[4,5,6]])
b = np.array([0,1])
What error occurs when trying to multiply the array X with the array b without reshaping?
X = np.array([[1,2,3],[4,5,6]]) b = np.array([0,1]) What error occurs when trying to multiply the array X with the array b without reshaping?
Error: operands could not be broadcast together
Match the following operations with their type:
Match the following operations with their type:
Signup and view all the answers
The calculation of total requires using nested for-loops.
The calculation of total requires using nested for-loops.
Signup and view all the answers
What is the shape of vector x?
What is the shape of vector x?
Signup and view all the answers
Match the tasks to their descriptions based on the operations performed:
Match the tasks to their descriptions based on the operations performed:
Signup and view all the answers
Which of these vectors is being summed?
Which of these vectors is being summed?
Signup and view all the answers
What are the numerical elements of vector y?
What are the numerical elements of vector y?
Signup and view all the answers
The provided method for calculating the total utilizes broadcasting.
The provided method for calculating the total utilizes broadcasting.
Signup and view all the answers
What does the expression x[0:2]
evaluate to?
What does the expression x[0:2]
evaluate to?
Signup and view all the answers
The expression x[-1, :]
returns the first row of the array x.
The expression x[-1, :]
returns the first row of the array x.
Signup and view all the answers
What would be the output of x[:, [0,1]]
given the array x = np.array([[3, 2, 1], [4, 5, 6]])
?
What would be the output of x[:, [0,1]]
given the array x = np.array([[3, 2, 1], [4, 5, 6]])
?
Signup and view all the answers
The default START value for slicing when STEP is less than 0 is ___.
The default START value for slicing when STEP is less than 0 is ___.
Signup and view all the answers
x = np.array([[0,1,2], [0,1,2], [0,1,2]])
Which of the following expressions would result in an output shape of (2, 1)?
x = np.array([[0,1,2], [0,1,2], [0,1,2]])
Which of the following expressions would result in an output shape of (2, 1)?
Signup and view all the answers
The expression x[::-1, [2, 1, 0]]
reverses the order of the rows and selects the columns from right to left.
The expression x[::-1, [2, 1, 0]]
reverses the order of the rows and selects the columns from right to left.
Signup and view all the answers
What happens if you use A[:, :2]
on the array A
with shape (3, 3)?
What happens if you use A[:, :2]
on the array A
with shape (3, 3)?
Signup and view all the answers
x = np.array([[0,1,2], [0,1,2], [0,1,2]])
Match the following numpy slicing expressions with their expected output shape:
x = np.array([[0,1,2], [0,1,2], [0,1,2]])
Match the following numpy slicing expressions with their expected output shape:
Signup and view all the answers
What is the primary purpose of the numpy.random sub-module?
What is the primary purpose of the numpy.random sub-module?
Signup and view all the answers
SciPy is primarily designed for data visualization rather than numerical analysis.
SciPy is primarily designed for data visualization rather than numerical analysis.
Signup and view all the answers
What function in numpy.random would you use to create an array of uniformly distributed random numbers?
What function in numpy.random would you use to create an array of uniformly distributed random numbers?
Signup and view all the answers
The ______ function in SciPy is used for optimization tasks such as linear programming.
The ______ function in SciPy is used for optimization tasks such as linear programming.
Signup and view all the answers
Which of the following functions is used for obtaining the mean value in NumPy?
Which of the following functions is used for obtaining the mean value in NumPy?
Signup and view all the answers
What does the np.random.seed(N) function do?
What does the np.random.seed(N) function do?
Signup and view all the answers
Match the following SciPy modules with their functions:
Match the following SciPy modules with their functions:
Signup and view all the answers
It is advisable to mix the numpy.random and the built-in random module in your projects.
It is advisable to mix the numpy.random and the built-in random module in your projects.
Signup and view all the answers
What does the function np.min(A, axis = 0)
return?
What does the function np.min(A, axis = 0)
return?
Signup and view all the answers
p = [p11 .... p1n]
[pk1.....pkn]
where each row gives n prediction by k ml method
obs = [obs1 ... obsn]
What does np.max(np.mean((P-obs)**2, axis = 1))
compute?
p = [p11 .... p1n]
[pk1.....pkn]
where each row gives n prediction by k ml method
obs = [obs1 ... obsn]
What does np.max(np.mean((P-obs)**2, axis = 1))
compute?
Signup and view all the answers
The numpy function np.min(A, axis = 1)
returns the minimum values along the ______.
The numpy function np.min(A, axis = 1)
returns the minimum values along the ______.
Signup and view all the answers
Match the numpy functions to their descriptions:
Match the numpy functions to their descriptions:
Signup and view all the answers
If obs
contains the actual observed values, which variable represents the predicted values?
If obs
contains the actual observed values, which variable represents the predicted values?
Signup and view all the answers
The MSE can never be negative.
The MSE can never be negative.
Signup and view all the answers
What does the operation 𝑃𝑘𝑖 − 𝑜𝑏𝑠𝑖
represent in the context of MSE?
What does the operation 𝑃𝑘𝑖 − 𝑜𝑏𝑠𝑖
represent in the context of MSE?
Signup and view all the answers
Which method can be used to find the minimum value in a NumPy array?
Which method can be used to find the minimum value in a NumPy array?
Signup and view all the answers
The method np.any() checks if all elements in an array are true.
The method np.any() checks if all elements in an array are true.
Signup and view all the answers
What will the output of np.all(b) be if b is defined as np.array([1, 1, 0, 0])?
What will the output of np.all(b) be if b is defined as np.array([1, 1, 0, 0])?
Signup and view all the answers
To check if there are any negative values in an array A, use the function np.any(A < ______).
To check if there are any negative values in an array A, use the function np.any(A < ______).
Signup and view all the answers
Match the following NumPy functions with their descriptions:
Match the following NumPy functions with their descriptions:
Signup and view all the answers
What result does np.all(A < 0, axis=0) return?
What result does np.all(A < 0, axis=0) return?
Signup and view all the answers
Methods in NumPy can be applied to lists in Python.
Methods in NumPy can be applied to lists in Python.
Signup and view all the answers
Which function is used to determine if there are negative values in an array A?
Which function is used to determine if there are negative values in an array A?
Signup and view all the answers
Study Notes
Course Information
- Course name: BMAN73701 Programming in Python for Business Analytics
- Week: 3, Lecture 2
- Topic: Numerical Analysis
- Instructor: Manuel López-Ibáñez
- Email: [email protected]
- Office hours: Monday 4pm-5pm, Friday 9am-10am
- Calendar link: https://calendly.com/manuel-lopez-ibanez
- Discussion board: Blackboard
- Additional course materials:
- Complete Python code available on Blackboard
Numerical Analysis (NumPy)
- NumPy is a Python library for numerical computations.
- Offers fast computations with large multi-dimensional arrays.
- Includes functions for working with vectors and matrices.
- Well integrated with libraries such as Pandas and Matplotlib.
- Scikit-learn (ML) software uses NumPy for its foundational operations.
NumPy Arrays vs Lists
- NumPy arrays are different from Python lists.
- NumPy arrays support element-wise operations, while Python lists do not.
- NumPy arrays are typically faster for numerical computation.
- Examples use cases where list computations are not appropriate provided
Indexing with NumPy
- Slicing NumPy arrays is similar to slicing lists.
- NumPy allows for boolean indexing.
- The methods for NumPy arrays are different from those for Python lists.
Slices and Views
- Slicing in NumPy creates views, not copies.
- Modifying a slice may affect the original array.
- Use
.copy()
to create an independent copy.
Broadcasting
- Broadcasting allows element-wise operations between NumPy arrays of different shapes.
- Specific rules are followed when broadcasting, such as reshaping.
Aggregations (Reductions)
- NumPy's aggregate functions like sum, min, max, mean, all, and any work along given axis values.
- These operations can return a scalar value or a reduced-dimension array.
Sorting
- NumPy offers direct sorting functions and indirect sorting for a range of operations.
-
np.sort()
,np.argsort()
,np.argmin()
,np.argmax()
are available functions.
scipy
Library
-
scipy
is a Python library used for advanced numerical computations. - It provides a range of functions beyond NumPy's capabilities, like optimization, linear algebra, statistics, and more
- Useful supplementary information to NumPy functions
Next Week Topics
- Introduction to pandas for data manipulation and analysis
- Matplotlib for advanced data visualization and plotting.
- Matplotlib concepts needed for complicated plots.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Test your knowledge on Numerical Analysis using NumPy in Python for the BMAN73701 course. This quiz covers the differences between NumPy arrays and Python lists, as well as their applications in business analytics. Prepare to apply your understanding of numerical computations and array operations.