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.
Display the source blob
Display the rendered blob
Raw
{
"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
}
@ngbala6
Copy link
Author

ngbala6 commented May 15, 2021

gisting the Mean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment