{"id":2263,"date":"2023-07-23T00:54:54","date_gmt":"2023-07-23T00:54:54","guid":{"rendered":"https:\/\/statorials.org\/it\/loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero\/"},"modified":"2023-07-23T00:54:54","modified_gmt":"2023-07-23T00:54:54","slug":"loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero\/","title":{"rendered":"Come risolvere il problema: l&#39;oggetto &#39;numpy.float64&#39; non pu\u00f2 essere interpretato come un int"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Un errore che potresti riscontrare durante l&#8217;utilizzo di NumPy \u00e8:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #ff0000;\">TypeError<\/span> : 'numpy.float64' object cannot be interpreted as an integer\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo errore si verifica quando fornisci un float a una funzione che prevede un numero intero.<\/span><\/p>\n<p> <span style=\"color: #000000;\">L&#8217;esempio seguente mostra come correggere questo errore nella pratica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Come riprodurre l&#8217;errore<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di provare a utilizzare il seguente ciclo for per stampare numeri diversi in un array NumPy:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n\n<span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#define array of values<\/span>\ndata = np. <span style=\"color: #3366ff;\">array<\/span> ([3.3, 4.2, 5.1, 7.7, 10.8, 11.4])\n\n<span style=\"color: #008080;\">#use for loop to print out range of values at each index\n<\/span><span style=\"color: #008000;\">for<\/span> i <span style=\"color: #008000;\">in<\/span> range(len(data)):\n    <span style=\"color: #008000;\">print<\/span> (range(data[i]))\n\n<span style=\"color: #ff0000;\">TypeError<\/span> : 'numpy.float64' object cannot be interpreted as an integer\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Riceviamo un errore perch\u00e9 la funzione <strong>range()<\/strong> prevede un numero intero, ma i valori nell&#8217;array NumPy sono float.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Come correggere l&#8217;errore<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Esistono due modi per correggere rapidamente questo errore:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: utilizzare la funzione int()<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Un modo per correggere questo errore \u00e8 semplicemente racchiudere la chiamata con <strong>int()<\/strong> come segue:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n\n<span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#define array of values<\/span>\ndata = np. <span style=\"color: #3366ff;\">array<\/span> ([3.3, 4.2, 5.1, 7.7, 10.8, 11.4])\n\n<span style=\"color: #008080;\">#use for loop to print out range of values at each index\n<\/span><span style=\"color: #008000;\">for<\/span> i <span style=\"color: #008000;\">in<\/span> range(len(data)):\n    <span style=\"color: #008000;\">print<\/span> (range(int(data[i])))\n\nrange(0, 3)\nrange(0, 4)\nrange(0, 5)\nrange(0, 7)\nrange(0, 10)\nrange(0, 11)\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Utilizzando la funzione <strong>int()<\/strong> , convertiamo ogni valore float nell&#8217;array NumPy in un numero intero per evitare il <strong>TypeError<\/strong> che abbiamo riscontrato in precedenza.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: utilizzare la funzione .astype(int).<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Un altro modo per correggere questo errore \u00e8 convertire prima i valori dell&#8217;array NumPy in numeri interi:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n\n<span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#define array of values\n<\/span>data = np. <span style=\"color: #3366ff;\">array<\/span> ([3.3, 4.2, 5.1, 7.7, 10.8, 11.4])\n\n<span style=\"color: #008080;\">#convert array of floats to array of integers<\/span>\ndata_int = data. <span style=\"color: #3366ff;\">astype<\/span> (int)\n\n<span style=\"color: #008080;\">#use for loop to print out range of values at each index\n<\/span><span style=\"color: #008000;\">for<\/span> i <span style=\"color: #008000;\">in<\/span> range(len(data)):\n    <span style=\"color: #008000;\">print<\/span> (range(data[i]))\n\nrange(0, 3)\nrange(0, 4)\nrange(0, 5)\nrange(0, 7)\nrange(0, 10)\nrange(0, 11)<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Utilizzando questo metodo evitiamo nuovamente il <strong>TypeError<\/strong> .<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">I seguenti tutorial spiegano come correggere altri errori comuni in Python:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/errore-chiave-panda\/\" target=\"_blank\" rel=\"noopener\">Come correggere l&#8217;errore chiave nei Panda<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/valueerror-non-puo-convertire-float-nan-in-intero\/\" target=\"_blank\" rel=\"noopener\">Come risolvere il problema: ValueError: impossibile convertire float NaN in int<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/non-e-stato-possibile-trasmettere-gli-operandi-con-i-moduli\/\" target=\"_blank\" rel=\"noopener\">Come risolvere il problema: ValueError: non \u00e8 stato possibile trasmettere gli operandi con le forme<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Un errore che potresti riscontrare durante l&#8217;utilizzo di NumPy \u00e8: TypeError : &#8216;numpy.float64&#8242; object cannot be interpreted as an integer Questo errore si verifica quando fornisci un float a una funzione che prevede un numero intero. L&#8217;esempio seguente mostra come correggere questo errore nella pratica. Come riprodurre l&#8217;errore Supponiamo di provare a utilizzare il seguente [&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":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Come risolvere il problema: l&#039;oggetto &#039;numpy.float64&#039; non pu\u00f2 essere interpretato come un numero intero - Stology<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come correggere il seguente errore in Python: l&#039;oggetto &#039;numpy.float64&#039; non pu\u00f2 essere interpretato come un numero intero.\" \/>\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\/it\/loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come risolvere il problema: l&#039;oggetto &#039;numpy.float64&#039; non pu\u00f2 essere interpretato come un numero intero - Stology\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come correggere il seguente errore in Python: l&#039;oggetto &#039;numpy.float64&#039; non pu\u00f2 essere interpretato come un numero intero.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-23T00:54:54+00:00\" \/>\n<meta name=\"author\" content=\"Benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero\/\",\"url\":\"https:\/\/statorials.org\/it\/loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero\/\",\"name\":\"Come risolvere il problema: l&#39;oggetto &#39;numpy.float64&#39; non pu\u00f2 essere interpretato come un numero intero - Stology\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-23T00:54:54+00:00\",\"dateModified\":\"2023-07-23T00:54:54+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come correggere il seguente errore in Python: l&#39;oggetto &#39;numpy.float64&#39; non pu\u00f2 essere interpretato come un numero intero.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come risolvere il problema: l&#39;oggetto &#39;numpy.float64&#39; non pu\u00f2 essere interpretato come un int\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/it\/#website\",\"url\":\"https:\/\/statorials.org\/it\/\",\"name\":\"Statorials\",\"description\":\"La tua guida all&#039;alfabetizzazione statistica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/it\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\",\"name\":\"Benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin anderson\"},\"description\":\"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9\",\"sameAs\":[\"https:\/\/statorials.org\/it\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Come risolvere il problema: l&#39;oggetto &#39;numpy.float64&#39; non pu\u00f2 essere interpretato come un numero intero - Stology","description":"Questo tutorial spiega come correggere il seguente errore in Python: l&#39;oggetto &#39;numpy.float64&#39; non pu\u00f2 essere interpretato come un numero intero.","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\/it\/loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero\/","og_locale":"it_IT","og_type":"article","og_title":"Come risolvere il problema: l&#39;oggetto &#39;numpy.float64&#39; non pu\u00f2 essere interpretato come un numero intero - Stology","og_description":"Questo tutorial spiega come correggere il seguente errore in Python: l&#39;oggetto &#39;numpy.float64&#39; non pu\u00f2 essere interpretato come un numero intero.","og_url":"https:\/\/statorials.org\/it\/loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero\/","og_site_name":"Statorials","article_published_time":"2023-07-23T00:54:54+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero\/","url":"https:\/\/statorials.org\/it\/loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero\/","name":"Come risolvere il problema: l&#39;oggetto &#39;numpy.float64&#39; non pu\u00f2 essere interpretato come un numero intero - Stology","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-23T00:54:54+00:00","dateModified":"2023-07-23T00:54:54+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come correggere il seguente errore in Python: l&#39;oggetto &#39;numpy.float64&#39; non pu\u00f2 essere interpretato come un numero intero.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/loggetto-numpy-float64-non-puo-essere-interpretato-come-un-numero-intero\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come risolvere il problema: l&#39;oggetto &#39;numpy.float64&#39; non pu\u00f2 essere interpretato come un int"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/it\/#website","url":"https:\/\/statorials.org\/it\/","name":"Statorials","description":"La tua guida all&#039;alfabetizzazione statistica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/it\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae","name":"Benjamin anderson","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Benjamin anderson"},"description":"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9","sameAs":["https:\/\/statorials.org\/it"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2263"}],"collection":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/comments?post=2263"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2263\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=2263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=2263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=2263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}