{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import scipy.spatial" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "clusters = 3\n", "mean = np.random.randint(5, size=clusters)\n", "sd = [0.25, 0.25, 0.3]\n", "dim = 2\n", "nb = 50\n", "K= clusters" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def gen_points(mean=1,sd=0.5, nb=100, dim=2, clusters=2):\n", " size = []\n", " # for i in range(0,dim):\n", " size.append(nb)\n", " size.append(dim)\n", " points = np.random.normal(mean[0],sd[0],size=size)\n", " for i in range(1,clusters):\n", " points = np.concatenate((points,np.random.normal(mean[i],sd[i],size=size)),axis=0)\n", " \n", " return points" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "def distance(points,Pc): \n", " return scipy.spatial.distance.cdist(points[:,:], Pc[:,:])" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "points = gen_points(mean,sd,nb,dim,clusters)\n", "dist = distance(points,points)\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.8.10 64-bit", "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.10" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" } } }, "nbformat": 4, "nbformat_minor": 2 }