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 (B)

    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 (B)</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 (B)</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 (A)</p> Signup and view all the answers

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

    <p>x[[0, 1]] (A), x[range(2)] (C)</p> Signup and view all the answers

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

    <p>False (B)</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] (B)</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 (A)</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 (A)</p> Signup and view all the answers

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

    <p>False (B)</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 (A)</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 (B)</p> Signup and view all the answers

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

    <p>The minimum along the rows. (D)</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 (D)</p> Signup and view all the answers

    The MSE can never be negative.

    <p>True (A)</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() (C)</p> Signup and view all the answers

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

    <p>False (B)</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 (C)</p> Signup and view all the answers

    Methods in NumPy can be applied to lists in Python.

    <p>False (B)</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

    Flashcards

    Pairwise Product Calculation

    Calculating the sum of all possible products obtained by multiplying corresponding elements from each of the two vectors.

    Vector Element Pairwise Product

    The product of corresponding elements from the input vectors.

    Vector Summation (Total)

    Adding up the results of all pairwise products of the elements across the two vectors.

    NumPy's Vectorized Operation:

    A computational approach that utilizes optimized array operations for efficiency; avoiding explicit loops (iterating through entries one by one).

    Signup and view all the flashcards

    Nested for-loops (Iterative Calculation)

    A traditional programming concept involving loops inside loops to process datasets element by element.

    Signup and view all the flashcards

    Vector Reshaping

    Changing the dimensional structure of a vector or array to fit the requirements.

    Signup and view all the flashcards

    Vector Sum of Products (np.sum)

    NumPy function used to sum the products of corresponding elements.

    Signup and view all the flashcards

    Broadcasting

    A technique in NumPy that allows array operations between arrays of different shapes.

    Signup and view all the flashcards

    Array slicing (Python)

    Extracting portions of an array using specific indexes (rows and columns).

    Signup and view all the flashcards

    Slicing with :

    Selecting a range of elements in an array with colon notation. x[start:end:step]

    Signup and view all the flashcards

    Start index 0

    The first index of the array or the first element in a list/array.

    Signup and view all the flashcards

    Negative index -1

    Refers to the last element of an array/list.

    Signup and view all the flashcards

    Boolean Indexing

    Selecting elements based on whether a condition is True or False.

    Signup and view all the flashcards

    Array x[row, column]

    Accessing elements at a specified row and column position within a 2-D array.

    Signup and view all the flashcards

    x[:, 1]

    Select all rows from a 2D array, but only the second column (index 1).

    Signup and view all the flashcards

    x[-1, :] Output

    Select the last row (index -1) and all columns from a 2D array.

    Signup and view all the flashcards

    NumPy Broadcasting

    A mechanism in NumPy that allows mathematical operations between arrays of different shapes, providing a more concise and efficient way to manipulate data.

    Signup and view all the flashcards

    Incompatible Array Shapes

    When NumPy arrays have shapes that don't allow for broadcasting, an error occurs because operations can't be performed element-wise in a consistent manner.

    Signup and view all the flashcards

    Reshaping Arrays

    Process of changing the dimensions (rows, columns) of a NumPy array without changing the total number of elements.

    Signup and view all the flashcards

    Element-wise Multiplication

    Multiplication where the corresponding elements of each array are multiplied together.

    Signup and view all the flashcards

    Aggregation Operations

    NumPy functions like sum(), min(), max(), mean() that compute a single output value from an array or array subset.

    Signup and view all the flashcards

    np.min(A)

    Finds the minimum value in a NumPy array A.

    Signup and view all the flashcards

    np.min(A, axis=0)

    Finds the minimum value along each column of a NumPy array A.

    Signup and view all the flashcards

    np.min(A, axis=1)

    Finds the minimum value along each row of a NumPy array A.

    Signup and view all the flashcards

    maxMSE calculation

    Calculates the maximum Mean Squared Error (MSE) from predictions (P) and observations (obs).

    Signup and view all the flashcards

    maxMSE formula

    The formula for finding maxMSE is maxMSE = np.max(np.mean((P-obs)**2, axis=1))

    Signup and view all the flashcards

    Matrix P

    A matrix where each row represents the predictions from a machine learning method across all observations, and each column represents a single observation.

    Signup and view all the flashcards

    Vector obs

    A vector containing the actual observed values for each observation.

    Signup and view all the flashcards

    Mean Squared Error (MSE)

    A measure of the average squared difference between predicted and actual values.

    Signup and view all the flashcards

    NumPy Methods

    Functions that operate on NumPy arrays, providing specific functionalities. They can be accessed using the dot notation (.) on the array object.

    Signup and view all the flashcards

    In-place Array Modification

    Some NumPy methods directly change the contents of the original array without creating a copy.

    Signup and view all the flashcards

    Boolean Arrays

    Arrays holding only True or False values, representing conditions on data.

    Signup and view all the flashcards

    np.any(A < 0)

    Checks for the presence of at least one negative value in the array 'A'.

    Signup and view all the flashcards

    np.all(A < 0)

    Checks if all values in the array 'A' are negative.

    Signup and view all the flashcards

    np.all(A < 0, axis = 0)

    Checks for columns in the array 'A' where all values are negative.

    Signup and view all the flashcards

    np.any(A < 0, axis = 1)

    Checks for rows in the array 'A' where at least one value is negative.

    Signup and view all the flashcards

    axis in NumPy

    A parameter used in some NumPy functions to specify the direction of operation, such as along rows (axis=0) or columns (axis=1).

    Signup and view all the flashcards

    NumPy's random Module

    A submodule of NumPy that provides functions for generating random numbers, distributions, and permutations.

    Signup and view all the flashcards

    What is np.random.seed(N) used for?

    Sets the initial state of the random number generator. When the seed is the same, you'll get the same sequence of random numbers.

    Signup and view all the flashcards

    SciPy Library

    A library built on top of NumPy designed for numerical analysis and scientific computing. It provides advanced functions for optimization, linear algebra, and statistics.

    Signup and view all the flashcards

    scipy.optimize

    A submodule within SciPy that offers functions for solving optimization problems. It handles tasks like maximizing/minimizing functions, both linear and non-linear.

    Signup and view all the flashcards

    scipy.linalg

    A submodule within SciPy for faster and more robust linear algebra operations compared to NumPy's np.linalg.

    Signup and view all the flashcards

    scipy.stats

    A SciPy submodule focused on statistical functions, distributions, hypothesis testing, and calculations like trimmed and geometric means.

    Signup and view all the flashcards

    Aggregations (Reductions)

    Functions like sum, min, max, mean, all, any that condense data into a single value, summarizing its key characteristics.

    Signup and view all the flashcards

    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

    Week 2: Introduction to NumPy
    37 questions
    NumPy Arrays and Linear Algebra
    27 questions
    Use Quizgecko on...
    Browser
    Browser