Skip to content

Instantly share code, notes, and snippets.

@ngbala6
Last active May 15, 2021 08:50
Show Gist options
  • Select an option

  • Save ngbala6/211ac319126530e042072a9491d365b2 to your computer and use it in GitHub Desktop.

Select an option

Save ngbala6/211ac319126530e042072a9491d365b2 to your computer and use it in GitHub Desktop.

Revisions

  1. ngbala6 revised this gist May 15, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mean.ipynb
    Original file line number Diff line number Diff line change
    @@ -87,7 +87,7 @@
    "cell_type": "markdown",
    "metadata": {},
    "source": [
    "### Using Statistics package"
    "### Using statistics package"
    ]
    },
    {
  2. ngbala6 created this gist May 15, 2021.
    139 changes: 139 additions & 0 deletions mean.ipynb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,139 @@
    {
    "cells": [
    {
    "cell_type": "markdown",
    "metadata": {},
    "source": [
    "### Import Packages"
    ]
    },
    {
    "cell_type": "code",
    "execution_count": 3,
    "metadata": {},
    "outputs": [],
    "source": [
    "import statistics\n",
    "import numpy as np"
    ]
    },
    {
    "cell_type": "markdown",
    "metadata": {},
    "source": [
    "### Sample Data"
    ]
    },
    {
    "cell_type": "code",
    "execution_count": 4,
    "metadata": {},
    "outputs": [],
    "source": [
    "data = [1,2,4,5,6,76,8,45]"
    ]
    },
    {
    "cell_type": "markdown",
    "metadata": {},
    "source": [
    "### Using Formula without Python Packages"
    ]
    },
    {
    "cell_type": "code",
    "execution_count": 6,
    "metadata": {},
    "outputs": [
    {
    "name": "stdout",
    "output_type": "stream",
    "text": [
    "18.375\n"
    ]
    }
    ],
    "source": [
    "mean = sum(data)/len(data)\n",
    "\n",
    "print(mean)"
    ]
    },
    {
    "cell_type": "markdown",
    "metadata": {},
    "source": [
    "### Using numpy package"
    ]
    },
    {
    "cell_type": "code",
    "execution_count": 7,
    "metadata": {},
    "outputs": [
    {
    "name": "stdout",
    "output_type": "stream",
    "text": [
    "18.375\n"
    ]
    }
    ],
    "source": [
    "print(np.mean(data))"
    ]
    },
    {
    "cell_type": "markdown",
    "metadata": {},
    "source": [
    "### Using Statistics package"
    ]
    },
    {
    "cell_type": "code",
    "execution_count": 8,
    "metadata": {},
    "outputs": [
    {
    "name": "stdout",
    "output_type": "stream",
    "text": [
    "18.375\n"
    ]
    }
    ],
    "source": [
    "print(statistics.mean(data))"
    ]
    },
    {
    "cell_type": "code",
    "execution_count": null,
    "metadata": {},
    "outputs": [],
    "source": []
    }
    ],
    "metadata": {
    "kernelspec": {
    "display_name": "Python 3",
    "language": "python",
    "name": "python3"
    },
    "language_info": {
    "codemirror_mode": {
    "name": "ipython",
    "version": 3
    },
    "file_extension": ".py",
    "mimetype": "text/x-python",
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
    "version": "3.7.4"
    }
    },
    "nbformat": 4,
    "nbformat_minor": 4
    }