Lecture 2

This commit is contained in:
judsonupchurch 2024-10-20 01:20:28 +00:00
parent d75be29418
commit 2a457caa2b

View File

@ -170,6 +170,91 @@
"output = np.dot(inputs, weights) + bias\n",
"print(output)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Layer of Neurons Using Numpy"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[4.8 1.21 2.385]\n",
"[4.8 1.21 2.385]\n"
]
}
],
"source": [
"import numpy as np\n",
"\n",
"inputs = [1.0, 2.0, 3.0, 2.5]\n",
"weights = np.array([\n",
" [0.2, 0.8, -0.5, 1],\n",
" [0.5, -0.91, 0.26, -0.5],\n",
" [-0.26, -0.27, 0.17, 0.87]\n",
"])\n",
"biases = [2.0, 3.0, 0.5]\n",
"\n",
"layer_outputs = np.dot(weights, inputs) + biases\n",
"# must be dot(weights, inputs), not dot(inputs, weights)\n",
"# this takes the dot each row of the weights by the column of inputs (remember the second term is transposed)\n",
"print(layer_outputs)\n",
"\n",
"layer_outputs_2 = np.dot(inputs, weights.T) + biases\n",
"# this takes each input and multiplies by the weight. also correct.\n",
"print(layer_outputs_2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Layer of Neurons and Batch of Data Using Numpy\n",
"Batch of data is simply a set of inputs."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 4.8 1.21 2.385]\n",
" [ 8.9 -1.81 0.2 ]\n",
" [ 1.41 1.051 0.026]]\n"
]
}
],
"source": [
"import numpy as np\n",
"\n",
"inputs = [ # Batch of inputs\n",
" [1.0, 2.0, 3.0, 2.5], \n",
" [2.0, 5.0, -1.0, 2.0], \n",
" [-1.5, 2.7, 3.3, -0.8]\n",
"]\n",
"weights = np.array([\n",
" [0.2, 0.8, -0.5, 1],\n",
" [0.5, -0.91, 0.26, -0.5],\n",
" [-0.26, -0.27, 0.17, 0.87]\n",
"])\n",
"biases = [2.0, 3.0, 0.5]\n",
"\n",
"outputs = np.dot(inputs, weights.T) + biases\n",
"# For every row of inputs, compute the dot of input set and weights\n",
"print(outputs)"
]
}
],
"metadata": {