Gasper Spagnolo 2022-08-13 19:02:12 +02:00
commit 88c2b949e8
3 changed files with 6849 additions and 0 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,657 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "31687c76",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "markdown",
"id": "5cfbcfd9",
"metadata": {},
"source": [
"## DataTypes & Attributes"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "d8e5c7e2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 2, 3])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# NumPy's main datatype is ndarray\n",
"a1 = np.array([1, 2, 3])\n",
"a1"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "a33f7c97",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"numpy.ndarray"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(a1)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "b9b415d9",
"metadata": {},
"outputs": [],
"source": [
"a2 = np.array([[1, 2.0, 3.3],\n",
" [4, 5, 6.5]])\n",
"a3 = np.array([[[1, 2, 3],\n",
" [4, 5, 6],\n",
" [7, 8, 9]],\n",
" [[10, 11, 12],\n",
" [13, 14, 15],\n",
" [16, 17, 18]]])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "cd071ecf",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1. , 2. , 3.3],\n",
" [4. , 5. , 6.5]])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a2"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "1d2c1045",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[[ 1, 2, 3],\n",
" [ 4, 5, 6],\n",
" [ 7, 8, 9]],\n",
"\n",
" [[10, 11, 12],\n",
" [13, 14, 15],\n",
" [16, 17, 18]]])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a3"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "e3fbbebb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3,)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a1.shape"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "43dc0c6d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(2, 3)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a2.shape"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "b949a2e4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(2, 3, 3)"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a3.shape"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "f8ab575a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1, 2, 3)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a1.ndim, a2.ndim, a3.ndim"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "f7ad5f19",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(dtype('int64'), dtype('float64'), dtype('int64'))"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a1.dtype, a2.dtype, a3.dtype"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "882c50f5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3, 6, 18)"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a1.size, a2.size, a3.size"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "1add28cb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(numpy.ndarray, numpy.ndarray, numpy.ndarray)"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(a1), type(a2), type(a3)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "e0c84cc7",
"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",
" <th>2</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" <td>3.3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>4.0</td>\n",
" <td>5.0</td>\n",
" <td>6.5</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 2\n",
"0 1.0 2.0 3.3\n",
"1 4.0 5.0 6.5"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create a DataFrame from a NumPy array\n",
"import pandas as pd\n",
"\n",
"df = pd.DataFrame(a2)\n",
"df"
]
},
{
"cell_type": "markdown",
"id": "3cafccec",
"metadata": {},
"source": [
"## 2. Creating arrays"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "ff67e8f5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 2, 3])"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sample_array = np.array([1, 2, 3])\n",
"sample_array"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "83278329",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dtype('int64')"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sample_array.dtype"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "fafba0e8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1., 1., 1.],\n",
" [1., 1., 1.]])"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ones = np.ones((2, 3))\n",
"ones"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "496eb840",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dtype('float64')"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ones.dtype"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "8679afec",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"numpy.ndarray"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(ones)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "c5cad563",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0., 0., 0.],\n",
" [0., 0., 0.]])"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"zeros = np.zeros((2, 3))\n",
"zeros"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "9758790b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 2, 4, 6, 8])"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"range_array = np.arange(0, 10, 2)\n",
"range_array"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "e120412c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[3, 4, 2, 5, 6],\n",
" [0, 1, 7, 9, 2],\n",
" [8, 5, 4, 0, 1]])"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"random_array = np.random.randint(0, 10, size=(3, 5))\n",
"random_array"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "92289cb3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"15"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"random_array.size"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "2e8fed36",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3, 5)"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"random_array.shape"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "9b9df235",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.44912645, 0.98510836, 0.97674192],\n",
" [0.67159454, 0.5610905 , 0.80301139],\n",
" [0.4803461 , 0.54147692, 0.93300764],\n",
" [0.13370648, 0.31868066, 0.91668974],\n",
" [0.48382992, 0.44254784, 0.22183905]])"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"random_array2 = np.random.random((5,3))\n",
"random_array2"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "e9a6a124",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.41154311, 0.67594683, 0.43359551],\n",
" [0.86838892, 0.48180592, 0.88852778],\n",
" [0.90123555, 0.73850576, 0.24385752],\n",
" [0.97303408, 0.80200642, 0.46062556],\n",
" [0.92454193, 0.15264643, 0.01139053]])"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"random_array3 = np.random.rand(5,3)\n",
"random_array3"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "35e7d231",
"metadata": {},
"outputs": [],
"source": [
"np.random.seed()"
]
}
],
"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.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

File diff suppressed because one or more lines are too long