{"id":8497,"date":"2019-02-07T17:43:16","date_gmt":"2019-02-07T16:43:16","guid":{"rendered":"http:\/\/www.valcon.it\/python\/?p=8497"},"modified":"2026-09-29T07:50:17","modified_gmt":"2026-09-29T05:50:17","slug":"op-vettori-1","status":"publish","type":"post","link":"https:\/\/www.valcon.it\/python\/op-vettori-1\/","title":{"rendered":"Operazioni con vettori &#8211; 1"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>Considera tre vettori della stessa lunghezza<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nvettA = &#x5B;2, 7, 1, 0, 1, 9, 9, 5]\nvettB = &#x5B;1, 2, 0, 4, 1, 9, 9, 7]\nvettC = &#x5B;1, 8, 0, 5, 1, 9, 9, 9]\n<\/pre><\/div>\n\n\n<p>Le operazioni seguenti producono un nuovo vettore.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Opposto \/ Prodotto per uno scalare<\/h2>\n\n\n\n<p>Scegli<\/p>\n\n\n\n<ul>\n<li><em>appendi<\/em> passo-passo gli elementi, moltiplicando per -1<\/li>\n\n\n\n<li>utilizza il <strong>prodotto per uno scalare<\/strong> con k=-1<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Somma<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-layout-1 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; gutter: false; title: ; notranslate\" title=\"\">\ndef somma(v1, v2): \n    n = len(v1)\n    w = &#x5B;] \n    for i in range(n): \n        x = v1&#x5B;i]+v2&#x5B;i]\n        w.append(x) \n    return w \n<\/pre><\/div><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; gutter: false; title: ; notranslate\" title=\"\">\ndef somma(v1, v2): \n    w = &#x5B;] \n    for i in range(len(v1)): \n        w.append(v1&#x5B;i]+v2&#x5B;i]) \n    return w \n<\/pre><\/div><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; gutter: false; title: ; notranslate\" title=\"\">\ndef somma(v1, v2): \n    w = &#x5B;] \n    for x, y in zip(v1, v2): \n        w.append(x+y) \n    return w \n<\/pre><\/div><\/div>\n<\/div>\n\n\n\n<p>Chiamate \/ Risultati<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nvettD = somma(vettA, vettB)  # &#x5B;2,7,1,0,1,9,9,5] + &#x5B;1,2,0,4,1,9,9,7] = &#x5B;3, 9,1,4,2,18,18,12] \nvettE = somma(vettA, vettC)  # &#x5B;2,7,1,0,1,9,9,5] + &#x5B;1,8,0,5,1,9,9,9] = &#x5B;3,15,1,5,2,18,18,14] \nvettF = somma(vettB, vettC)  # &#x5B;1,2,0,4,1,9,9,7] + &#x5B;1,8,0,5,1,9,9,9] = &#x5B;2,10,0,9,2,18,18,16]\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Differenza<\/h2>\n\n\n\n<p>Scegli<\/p>\n\n\n\n<ul>\n<li><em>appendi<\/em> passo-passo la sottrazione degli elementi, <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.valcon.it\/python\/wp-content\/ql-cache\/quicklatex.com-8d09cacf1bfb0eab9697771635d68e67_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#97;&#95;&#105;&#45;&#98;&#95;&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"50\" style=\"vertical-align: -3px;\"\/> <\/li>\n\n\n\n<li>utilizza la <strong>somma<\/strong> con l&#8217;<strong>opposto<\/strong> del secondo vettore<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Prodotto vettoriale<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.valcon.it\/pp\/prodotto-vettoriale\/\">Vedi discussione<\/a><\/p>\n\n\n\n<p>Gli indici in Python iniziano da zero&#8230;<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-layout-2 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ndef prodVett(a, b):\n    c = &#x5B;0, 0, 0]\n    c&#x5B;0] = a&#x5B;1]*b&#x5B;2]-a&#x5B;2]*b&#x5B;1]\n    c&#x5B;1] = a&#x5B;2]*b&#x5B;0]-a&#x5B;0]*b&#x5B;2]\n    c&#x5B;2] = a&#x5B;0]*b&#x5B;1]-a&#x5B;1]*b&#x5B;0]\n    return c\n<\/pre><\/div><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ndef prodVett(a, b):\n    c = &#x5B;]\n    c.append(a&#x5B;1]*b&#x5B;2]-a&#x5B;2]*b&#x5B;1])\n    c.append(a&#x5B;2]*b&#x5B;0]-a&#x5B;0]*b&#x5B;2])\n    c.append(a&#x5B;0]*b&#x5B;1]-a&#x5B;1]*b&#x5B;0])\n    return c\n<\/pre><\/div><\/div>\n<\/div>\n\n\n\n<p>Prova<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nvettA = &#x5B;1, 0, 0]\nvettB = &#x5B;0, 1, 0]\nvettC = &#x5B;0, 0, 1]\n\nvett1 = prodVett(vettA, vettA)  # &#x5B;0, 0, 0]\nvett2 = prodVett(vettA, vettB)  # &#x5B;0, 0, 1]\nvett3 = prodVett(vettA, vettC)  # &#x5B;0,-1, 0]\nvett4 = prodVett(vettB, vettA)  # &#x5B;0, 0,-1]\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">I due vettori sono compatibili?<\/h3>\n\n\n\n<p>Alcune operazioni hanno senso solo se i due vettori sono compatibili (hanno la stessa lunghezza&#8230;)<\/p>\n\n\n\n<p>Si potrebbe aggiungere un controllo preventivo<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ndef operazione(v1, v2):\n    n1 = len(v1)\n    n2 = len(v2)\n    if(n1 != n2): return None\n\n    # Esegue il compito, se supera il controllo precedente\n    # ...\n    # ...\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Considera tre vettori della stessa lunghezza Le operazioni seguenti producono un nuovo vettore. Opposto \/ Prodotto per uno scalare Scegli Somma Chiamate \/ Risultati Differenza Scegli Prodotto vettoriale Vedi discussione Gli indici in Python iniziano da zero&#8230; Prova I due vettori sono compatibili? Alcune operazioni hanno senso solo se i due vettori sono compatibili (hanno &#8230; <a title=\"Operazioni con vettori &#8211; 1\" class=\"read-more\" href=\"https:\/\/www.valcon.it\/python\/op-vettori-1\/\" aria-label=\"Leggi di pi\u00f9 su Operazioni con vettori &#8211; 1\">Leggi tutto<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[],"_links":{"self":[{"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/posts\/8497"}],"collection":[{"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/comments?post=8497"}],"version-history":[{"count":88,"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/posts\/8497\/revisions"}],"predecessor-version":[{"id":31364,"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/posts\/8497\/revisions\/31364"}],"wp:attachment":[{"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/media?parent=8497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/categories?post=8497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/tags?post=8497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}