Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
280 changes: 280 additions & 0 deletions numpy_#1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "1426cd93",
"metadata": {},
"source": [
"#### nympy task 1"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "4c6dff0e",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "3124b9a3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 1 6]\n",
" [ 2 8]\n",
" [ 3 11]\n",
" [ 3 10]\n",
" [ 1 7]]\n"
]
}
],
"source": [
"a = np.array([[1,6],\n",
" [2,8],\n",
" [3,11],\n",
" [3,10],\n",
" [1,7]])\n",
"print(a)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "0c26a132",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[2. 8.4]\n"
]
}
],
"source": [
"mean_a = np.mean(a, axis = 0)\n",
"print(mean_a)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "f548d9aa",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(5, 2)"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a.shape"
]
},
{
"cell_type": "markdown",
"id": "08a460ef",
"metadata": {},
"source": [
"#### nympy task 2"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "bb310327",
"metadata": {},
"outputs": [],
"source": [
"a_centered = a - mean_a"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "2cc48f6a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[-1. , -2.4],\n",
" [ 0. , -0.4],\n",
" [ 1. , 2.6],\n",
" [ 1. , 1.6],\n",
" [-1. , -1.4]])"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a_centered"
]
},
{
"cell_type": "markdown",
"id": "06c9cf90",
"metadata": {},
"source": [
"#### nympy task 3"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "d1d847ac",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([-2.4, -0.4, 2.6, 1.6, -1.4])"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a_centered.T[1]"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "6c638ade",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[-1.],\n",
" [ 0.],\n",
" [ 1.],\n",
" [ 1.],\n",
" [-1.]])"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a_centered[:,:1]"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "f2962a5f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.0"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a_centered_sp = np.dot(a_centered.T[1], a_centered.T[0]) \n",
"a_centered_sp / (a_centered.shape[0] - 1)"
]
},
{
"cell_type": "markdown",
"id": "5437a025",
"metadata": {},
"source": [
"#### nympy task 4"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "23547665",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.0"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.cov(a.T)[0, 1]"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "72bf00b5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1. , 2. ],\n",
" [2. , 4.3]])"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.cov(a.T)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.10.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading