{ "cells": [ { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# import numpy for doing the math/making matrices\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "# [[1, 2, 1.5], [3, 4, 5], [10, 5, 2]]\n", "arr = [[2, 3, 4, 6], [2, 2.5, 4, 4.5]]\n", "arr2 = [[1, 2, 1.5], [3, 4, 5], [10, 5, 2]]" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2.9166666666666665\n", "[[2.91666667 1.91666667]\n", " [1.91666667 1.41666667]]\n", "[[ 0.25 0.25 -1.25 ]\n", " [ 0.25 1. -4. ]\n", " [-1.25 -4. 16.33333333]]\n" ] } ], "source": [ "# calculate the variance/covariance\n", "# np.var(arr, ddof = 1)\n", "# np.cov(arr)\n", "# ddof = 1 means use bessel's correction\n", "print(np.var(arr[0], ddof = 1))\n", "print(np.cov(arr))\n", "print(np.cov(arr2))" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[ 1. 0.5 -0.61858957]\n", " [ 0.5 1. -0.98974332]\n", " [-0.61858957 -0.98974332 1. ]]\n" ] } ], "source": [ "# calculate the coref values\n", "# np.corrcoef(arr)\n", "print(np.corrcoef(arr2))" ] }, { "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.8.12" } }, "nbformat": 4, "nbformat_minor": 4 }