{"id":1116,"date":"2023-07-27T14:58:19","date_gmt":"2023-07-27T14:58:19","guid":{"rendered":"https:\/\/statorials.org\/nl\/euclidische-afstandspython\/"},"modified":"2023-07-27T14:58:19","modified_gmt":"2023-07-27T14:58:19","slug":"euclidische-afstandspython","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/euclidische-afstandspython\/","title":{"rendered":"Hoe de euclidische afstand in python te berekenen (met voorbeelden)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">De <strong>Euclidische afstand<\/strong> tussen twee vectoren A en B wordt als volgt berekend:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Euclidische afstand = \u221a <span style=\"border-top: 1px solid black;\">\u03a3(A <sub>i<\/sub> -B <sub>i<\/sub> ) <sup>2<\/sup><\/span><\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Om de Euclidische afstand tussen twee vectoren in Python te berekenen, kunnen we de functie <strong>numpy.linalg.norm<\/strong> gebruiken:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\"><span style=\"color: #008080;\">#import functions<\/span>\nimport <span style=\"color: #000000;\">numpy<\/span> as <span style=\"color: #000000;\">np<\/span>\nfrom<\/span> numpy. <span style=\"color: #008000;\"><span style=\"color: #3366ff;\">linalg<\/span> import<\/span> norm\n\n<span style=\"color: #008080;\">#define two vectors\n<\/span>a = np.array([2, 6, 7, 7, 5, 13, 14, 17, 11, 8])\nb = np.array([3, 5, 5, 3, 7, 12, 13, 19, 22, 7])\n\n<span style=\"color: #008080;\">#calculate Euclidean distance between the two vectors<\/span> \nnorm(ab)\n\n12.409673645990857<\/strong>\n<\/pre>\n<p> <span style=\"color: #000000;\">De Euclidische afstand tussen de twee vectoren blijkt <strong>12,40967<\/strong> te zijn.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Merk op dat deze functie een waarschuwingsbericht zal produceren als de twee vectoren niet dezelfde lengte hebben:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\"><span style=\"color: #008080;\">#import functions<\/span>\nimport <span style=\"color: #000000;\">numpy<\/span> as <span style=\"color: #000000;\">np<\/span>\nfrom<\/span> numpy. <span style=\"color: #008000;\"><span style=\"color: #3366ff;\">linalg<\/span> import<\/span> norm\n\n<span style=\"color: #008080;\">#define two vectors\n<\/span>a = np.array([2, 6, 7, 7, 5, 13, 14])\nb = np.array([3, 5, 5, 3, 7, 12, 13, 19, 22, 7])\n\n<span style=\"color: #008080;\">#calculate Euclidean distance between the two vectors<\/span> \nnorm(ab)\n\n<span style=\"color: #993300;\">ValueError<\/span> : operands could not be broadcast together with shapes (7,) (10,) \n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Merk op dat we deze functie ook kunnen gebruiken om de Euclidische afstand tussen twee kolommen van een panda&#8217;s DataFrame te berekenen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\"><span style=\"color: #008080;\">#import functions\n<\/span>import <span style=\"color: #000000;\">pandas<\/span> as <span style=\"color: #000000;\">pd<\/span> \nimport <span style=\"color: #000000;\">numpy<\/span> as <span style=\"color: #000000;\">np<\/span>\nfrom<\/span> numpy. <span style=\"color: #008000;\"><span style=\"color: #3366ff;\">linalg<\/span> import<\/span> norm\n\n<span style=\"color: #008080;\">#define DataFrame with three columns\n<\/span>df = pd.DataFrame({'points': [25, 12, 15, 14, 19, 23, 25, 29],\n                   'assists': [5, 7, 7, 9, 12, 9, 9, 4],\n                   'rebounds': [11, 8, 10, 6, 6, 5, 9, 12]})\n\n<span style=\"color: #008080;\">#calculate Euclidean distance between 'points' and 'assists'<\/span> \nnorm(df[' <span style=\"color: #008000;\">points<\/span> '] - df[' <span style=\"color: #008000;\">assists<\/span> '])\n\n40.496913462633174\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">De Euclidische afstand tussen de twee kolommen blijkt <strong>40,49691<\/strong> te zijn.<\/span><\/p>\n<h3> <strong><span style=\"color: #000000;\">Opmerkingen<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\"><strong>1.<\/strong> Er zijn verschillende manieren om de Euclidische afstand in Python te berekenen, maar zoals <a href=\"https:\/\/stackoverflow.com\/questions\/1401712\/how-can-the-euclidean-distance-be-calculated-with-numpy\" target=\"_blank\" rel=\"noopener noreferrer\">deze Stack Overflow-thread uitlegt<\/a> , blijkt de hier uitgelegde methode de snelste te zijn.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>2.<\/strong> U kunt de volledige documentatie van de functie <strong>numpy.linalg.norm<\/strong> <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.linalg.norm.html\" target=\"_blank\" rel=\"noopener noreferrer\">hier<\/a> vinden.<\/span><\/p>\n<p> 3. U kunt <a href=\"https:\/\/en.wikipedia.org\/wiki\/Euclidean_distance\" target=\"_blank\" rel=\"noopener noreferrer\">deze Wikipedia-pagina<\/a> <span style=\"color: #000000;\"><strong>raadplegen<\/strong><\/span> <span style=\"color: #000000;\">voor meer informatie over de Euclidische afstand.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>De Euclidische afstand tussen twee vectoren A en B wordt als volgt berekend: Euclidische afstand = \u221a \u03a3(A i -B i ) 2 Om de Euclidische afstand tussen twee vectoren in Python te berekenen, kunnen we de functie numpy.linalg.norm gebruiken: #import functions import numpy as np from numpy. linalg import norm #define two vectors a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-1116","post","type-post","status-publish","format-standard","hentry","category-gids"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Hoe de Euclidische afstand in Python te berekenen (met voorbeelden) - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe je de Euclidische afstand in Python kunt berekenen, met verschillende voorbeelden.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/nl\/euclidische-afstandspython\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe de Euclidische afstand in Python te berekenen (met voorbeelden) - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe je de Euclidische afstand in Python kunt berekenen, met verschillende voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/euclidische-afstandspython\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-27T14:58:19+00:00\" \/>\n<meta name=\"author\" content=\"Dr.benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr.benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"1\u00a0Minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/euclidische-afstandspython\/\",\"url\":\"https:\/\/statorials.org\/nl\/euclidische-afstandspython\/\",\"name\":\"Hoe de Euclidische afstand in Python te berekenen (met voorbeelden) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-27T14:58:19+00:00\",\"dateModified\":\"2023-07-27T14:58:19+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe je de Euclidische afstand in Python kunt berekenen, met verschillende voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/euclidische-afstandspython\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/euclidische-afstandspython\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/euclidische-afstandspython\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe de euclidische afstand in python te berekenen (met voorbeelden)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/nl\/#website\",\"url\":\"https:\/\/statorials.org\/nl\/\",\"name\":\"Statorials\",\"description\":\"Uw gids voor statistische competentie\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/nl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\",\"name\":\"Dr.benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr.benjamin anderson\"},\"description\":\"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder\",\"sameAs\":[\"http:\/\/statorials.org\/nl\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Hoe de Euclidische afstand in Python te berekenen (met voorbeelden) - Statorials","description":"In deze tutorial wordt uitgelegd hoe je de Euclidische afstand in Python kunt berekenen, met verschillende voorbeelden.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/statorials.org\/nl\/euclidische-afstandspython\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe de Euclidische afstand in Python te berekenen (met voorbeelden) - Statorials","og_description":"In deze tutorial wordt uitgelegd hoe je de Euclidische afstand in Python kunt berekenen, met verschillende voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/euclidische-afstandspython\/","og_site_name":"Statorials","article_published_time":"2023-07-27T14:58:19+00:00","author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"1\u00a0Minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/euclidische-afstandspython\/","url":"https:\/\/statorials.org\/nl\/euclidische-afstandspython\/","name":"Hoe de Euclidische afstand in Python te berekenen (met voorbeelden) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-27T14:58:19+00:00","dateModified":"2023-07-27T14:58:19+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe je de Euclidische afstand in Python kunt berekenen, met verschillende voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/euclidische-afstandspython\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/euclidische-afstandspython\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/euclidische-afstandspython\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe de euclidische afstand in python te berekenen (met voorbeelden)"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/nl\/#website","url":"https:\/\/statorials.org\/nl\/","name":"Statorials","description":"Uw gids voor statistische competentie","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/nl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de"},{"@type":"Person","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219","name":"Dr.benjamin anderson","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/","url":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr.benjamin anderson"},"description":"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder","sameAs":["http:\/\/statorials.org\/nl"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/1116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/comments?post=1116"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/1116\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=1116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=1116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=1116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}