PyZombis aayush/sample_exercise@20dfdbe
  • Social
    • Runestone in social media:
      Follow @iRunestone Our Facebook Page
    • Help support us:
  • Search
    • Table of Contents
    • Book Index
  • User
    • Assignments
    • Practice
    • Change Course
    • Instructor's Page
    • Progress Page
    • Edit Profile
    • Change Password
    • Register
    • Login
    • Dark Mode
  • Scratch Activecode
  • Help
    • FAQ
    • Instructors Guide
    • About Runestone
    • Report A Problem
  • Numpy Exercise¶

    Introduction to Numpy¶

    NumPy is a Python library that provides support for large, multi-dimensional arrays and matrices, along with a collection of mathematical functions to operate on these arrays efficiently. It is widely used in scientific computing, data analysis, and machine learning due to its powerful array manipulation capabilities and efficient numerical operations.

    Numpy functions¶

    1. Mean (np.mean()) : Calculates the arithmetic mean (average) of elements along a specified axis in an array. It computes the sum of all elements and divides it by the number of elements.

    2. Median (np.median()): Computes the median, which is the middle value of a sorted array. If the array has an odd number of elements, the median is the middle value. If it has an even number, it’s the average of the two middle values.

    3. Standard Deviation (np.std()): Calculates the standard deviation, which measures the spread of data around the mean. It’s the square root of the variance, where variance is the average of the squared differences from the mean.

    4. Sort (np.sort()): Sorts the elements of an array along a specified axis. By default, it sorts the array in ascending order along the last axis. You can specify the axis along which to sort and whether to return a sorted copy or sort the array in place.

    See the code below to understand how these functions work.


    NumPy Quiz packages = ["numpy"] terminal = false

    Match the NumPy function with its description:

    Try numpy functions in the Python REPL below:

    import numpy as np # Create a NumPy array arr = np.array([1, 2, 3, 4, 5]) # Calculate mean mean = np.mean(arr) print("Mean of the array:", mean) # Calculate median median = np.median(arr) print("Median of the array:", median) # Sort the array sorted_arr = np.sort(arr) print("Sorted array:", sorted_arr) # Calculate standard deviation std_dev = np.std(arr) print("Standard deviation of the array:", std_dev)

    Instructions¶

    SHIFT + ENTER on the code cell below to see the quiz. Match the NumPy functions with their descriptions and click on the “Submit” button to check your answers.

    You have attempted of activities on this page

| Back to top

© Copyright 2021 Python Argentina et al.. Created using Runestone 5.8.1.