Commit 4cbd5423 by Paktalin

Section 6 exercises are done

parent 388fb65b
{
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from random import randrange\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"X = np.random.random(1000)\n",
"Y = [0]*1000"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"for i in range(1000):\n",
" for j in range(1000):\n",
" Y[i] += X[randrange(1000)]"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAEAZJREFUeJzt3X+M5HV9x/HnS0RsFBVkIRfwekbPn008zZaQEI1CVYSmQCvpkZbQij3bYKvG2p6mSe0Pk7Ot0rRpac+CXlt/ERE1glZCNdTUont64uFFoYj25MJB1IppSnPw7h/zXZxud25md2d2Zj/3fCSTmfnMd2ZeNzu8+Ox3P/OdVBWSpI3vMdMOIEkaDwtdkhphoUtSIyx0SWqEhS5JjbDQJakRFrokNcJCl6RGWOiS1IjHrueTnXLKKbVly5b1fEpJ2vD27t37QFXNDdtuXQt9y5YtLCwsrOdTStKGl+Tbo2znLhdJaoSFLkmNsNAlqREWuiQ1wkKXpEZY6JLUCAtdkhphoUtSIyx0SWrEun5SVJpVW3be+Ojle3ZdMMUk0uo5Q5ekRljoktQIC12SGmGhS1IjLHRJaoSrXKQlXPGijcoZuiQ1wkKXpEZY6JLUCAtdkhphoUtSI1zlIo3BoJUxrpjRenKGLkmNsNAlqRFDCz3J45N8MclXk9yR5A+68acnuS3Jn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ulCuTvOQo285adtj4+UcyjW8sOhv4uSTnA48HnpTkH6vql7vbH0ryXuC3u+sjHWJgHS2bn17O67ttbqBXLjBb+Qe+9kmeSu/Xyov7tp/17DfS+5vFbd02HwY+3V1ezH6w+0Pjk4HvrXPmfkd7378YIMkrgGd128/Sa09V3dudH05yA733yn1JNlXVoW6XyuJuxpnKDgPz3zpg85nLP7KqmtoJeCnwye7ypu489H413dVdvwD4VDd+FvDFaWY+Sv5dwGv6xr80y/n7s3fXfx3Ys2Sbmc5Ob0LyAPCsbvwK4Pru8pXA33SXtwPXTTv3gPfNqd35CfT+sHjOrL32wBOAE/su/yu9Pxb+KbCzG98J/MmsZT9a/r7bPwfM911/PvDV7mfydOBu4Lhpv29GOc3Sd4q+P8kcvTfBPnoFA71Pop5P7w8T/wX86nTiDbWL3r/hTcCP6O3bhY2Tfzs/3v+8aKazV+/wE78GXJ/kEeD7wGu6m68B/iHJXfRm5tunFHOYt3S7Yx4DXF1V/9yNz9JrfxpwQ/c35ccCH6iqTyf5EnBdkiuA7wCXdNvPUnYYnP9i4C+BOeDGJPuq6pVVdUeS64Cv09sFdmVVPTyt8CvhJ0UlqRF+UlSSGmGhS1IjLHRJaoSFLkmNsNAlqREWuiQ1wkKXpEZY6JLUiP8FBLclc5SS1qQAAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.hist(Y, bins=100)\n",
"plt.show()"
]
}
],
"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.5.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1., 0., 0.],\n",
" [0., 1., 0.],\n",
" [0., 0., 1.]])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"I3 = np.eye(3)\n",
"I3"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"A = np.array([[0.3, 0.6, 0.1],\n",
" [0.5, 0.2, 0.3],\n",
" [0.4, 0.1, 0.5]])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"def is_symmetric_automatic(matrix):\n",
" return (matrix == matrix.T).all()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"is_symmetric_automatic(A)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"is_symmetric_automatic(I3)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"def is_symmetric_manual(matrix):\n",
" matrix_T = np.zeros((len(matrix), len(matrix[0])))\n",
" for i in range(len(matrix)):\n",
" for j in range(len(matrix[i])):\n",
" matrix_T[i,j] = matrix[j,i]\n",
" return(matrix_T == matrix).all()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"is_symmetric_manual(A)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"is_symmetric_automatic(I3)"
]
}
],
"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.5.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"b = np.random.uniform(-1, 1, (1000, 2))"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>-0.131156</td>\n",
" <td>-0.189478</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>-0.016687</td>\n",
" <td>0.727200</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>-0.647184</td>\n",
" <td>0.910890</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>-0.492190</td>\n",
" <td>0.149369</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>-0.576105</td>\n",
" <td>0.550543</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1\n",
"0 -0.131156 -0.189478\n",
"1 -0.016687 0.727200\n",
"2 -0.647184 0.910890\n",
"3 -0.492190 0.149369\n",
"4 -0.576105 0.550543"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.DataFrame(b)\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"csv = df.to_csv(path_or_buf=\"data.csv\")"
]
}
],
"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.5.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment