BMAN73701 Week 3 Numerical Analysis Quiz
41 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

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?

  • array([[1, 0, 3], [0, 5, 6]])
  • Error: operands could not be broadcast together
  • array([[1, 2, 3], [4, 5, 6]])
  • array([[0, 2, 0], [0, 5, 0]]) (correct)
  • 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?

    Error: operands could not be broadcast together

    Match the following operations with their type:

    <p>sum = Aggregation operation mean = Aggregation operation reshape = Array manipulation broadcasting = Enables operations on different shaped arrays</p> Signup and view all the answers

    The calculation of total requires using nested for-loops.

    <p>False</p> Signup and view all the answers

    What is the shape of vector x?

    <p>4</p> Signup and view all the answers

    Match the tasks to their descriptions based on the operations performed:

    <p>Reshape = Alters the dimensions of an array Pairwise product = Multiplies corresponding elements from two arrays Sum = Calculates the aggregate of values Total = Final result of all pairwise products</p> Signup and view all the answers

    Which of these vectors is being summed?

    <p>The products of x and y elements</p> Signup and view all the answers

    What are the numerical elements of vector y?

    <p>2, 3, 4, 5</p> Signup and view all the answers

    The provided method for calculating the total utilizes broadcasting.

    <p>True</p> Signup and view all the answers

    What does the expression x[0:2] evaluate to?

    <p>x[[0, 1]]</p> Signup and view all the answers

    The expression x[-1, :] returns the first row of the array x.

    <p>False</p> 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]])?

    <p>array([[3, 2], [4, 5]])</p> Signup and view all the answers

    The default START value for slicing when STEP is less than 0 is ___.

    <p>len(x) - 1</p> 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)?

    <p>x[1:, :1]</p> 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.

    <p>True</p> Signup and view all the answers

    What happens if you use A[:, :2] on the array A with shape (3, 3)?

    <p>Selects the first two columns for all three rows.</p> 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:

    <p>x[:, 1:] = (3, 2) x[0:2, :] = (2, 3) x[:1, :] = (1, 3) x[-1, :] = (3,)</p> Signup and view all the answers

    What is the primary purpose of the numpy.random sub-module?

    <p>Random number generation</p> Signup and view all the answers

    SciPy is primarily designed for data visualization rather than numerical analysis.

    <p>False</p> Signup and view all the answers

    What function in numpy.random would you use to create an array of uniformly distributed random numbers?

    <p>np.random.rand</p> Signup and view all the answers

    The ______ function in SciPy is used for optimization tasks such as linear programming.

    <p>scipy.optimize</p> Signup and view all the answers

    Which of the following functions is used for obtaining the mean value in NumPy?

    <p>Both np.mean and np.average</p> Signup and view all the answers

    What does the np.random.seed(N) function do?

    <p>It initializes the random number generator with a seed value.</p> Signup and view all the answers

    Match the following SciPy modules with their functions:

    <p>scipy.optimize = Numerical optimization scipy.linalg = Linear algebra operations scipy.stats = Statistical tests numpy.random = Random number functions</p> Signup and view all the answers

    It is advisable to mix the numpy.random and the built-in random module in your projects.

    <p>False</p> Signup and view all the answers

    What does the function np.min(A, axis = 0) return?

    <p>The minimum along the rows.</p> 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>The maximum Mean Squared Error (MSE)</p> Signup and view all the answers

    The numpy function np.min(A, axis = 1) returns the minimum values along the ______.

    <p>columns</p> Signup and view all the answers

    Match the numpy functions to their descriptions:

    <p>np.min(A) = Returns the minimum value of the array np.min(A, axis=0) = Returns minimum along the row (per column) np.min(A, axis=1) = Returns minimum along the columns (per row) np.max(np.mean((P-obs)**2, axis = 1)) = Calculates maximum Mean Squared Error</p> Signup and view all the answers

    If obs contains the actual observed values, which variable represents the predicted values?

    <p>P</p> Signup and view all the answers

    The MSE can never be negative.

    <p>True</p> Signup and view all the answers

    What does the operation 𝑃𝑘𝑖 − 𝑜𝑏𝑠𝑖 represent in the context of MSE?

    <p>The difference between predicted values and actual observations</p> Signup and view all the answers

    Which method can be used to find the minimum value in a NumPy array?

    <p>A.min()</p> Signup and view all the answers

    The method np.any() checks if all elements in an array are true.

    <p>False</p> 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])?

    <p>false</p> Signup and view all the answers

    To check if there are any negative values in an array A, use the function np.any(A < ______).

    <p>0</p> Signup and view all the answers

    Match the following NumPy functions with their descriptions:

    <p>np.all() = Checks if all elements are true np.any() = Checks if any element is true np.logical_and() = Computes the logical AND operation np.logical_not() = Inverts the truth value of elements</p> Signup and view all the answers

    What result does np.all(A < 0, axis=0) return?

    <p>1 value per column</p> Signup and view all the answers

    Methods in NumPy can be applied to lists in Python.

    <p>False</p> Signup and view all the answers

    Which function is used to determine if there are negative values in an array A?

    <p>np.any(A &lt; 0)</p> 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.

    Quiz Team

    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.

    More Like This

    Use Quizgecko on...
    Browser
    Browser