直方圖是資料集分佈的圖形表示。它以一系列的條形圖的形式表示數據,其中每個條形圖代表的數據值範圍,條形圖的高度代表在該範圍內定義的數據值的頻率。
這些主要用於表示數值資料的分佈,如班級中的成績分佈,人口分佈或員工收入分佈等。
In histogram, x-axis represents the range of data values, divided into intervals and the y-axis represents the frequency of the range of data values within each bin. Histograms can be malized quers the freby sion the fidgrams can be malized queaching the freby sion the freby be ormalized viding the frebys the fidgrams can be malized viding the frebys the fidgrams can be malized viding the freby; total data values, which results to the relative frequency histogram where y-axis represents the data values of each bin.
Calculating histogram using Python Numpy
In python, for creating the histograms we have numpy, matplotlib and seaborn libraries. In Numpy, we have the function named histogram() to work with the histogram data.
文法
Following is the syntax for creating the histograms for the given range of data.
numpy.histogram(arr, bins, range, normed, weights, density)
Where,
的中文翻譯為:在哪裡,
arr 是輸入陣列
#bins 是用來表示資料的長條圖中的長條數
range 定義了直方圖中的值的範圍
normed 偏好密度參數
#weights是可選參數,用於每個資料值的權重
#密度是將直方圖資料歸一化為機率密度的參數。
The output of the histogram function will be a tuple containing the histogram counts and bin edges.
Example
在下面的範例中,我們使用Numpy的histogram()函數建立了一個直方圖。在這裡,我們將一個陣列作為輸入參數,將bins定義為10,這樣直方圖將被建立為10個bins,其餘的參數可以保持為none。
import numpy as np arr = np.array([10,20,25,40,35,23]) hist = np.histogram(arr,bins = 10) print("The histogram created:",hist)
Output
#The histogram created: (array([1, 0, 0, 1, 1, 1, 0, 0, 1, 1], dtype=int64), array([10., 13., 16., 19., 22., 25., 28., 31., 34., 37., 40.]))
Example
讓我們來看一個例子來理解numpy函式庫的histogram()函數。
import numpy as np arr = np.array([[20,20,25],[40,35,23],[34,22,1]]) hist = np.histogram(arr,bins = 20) print("The histogram created:",hist)
Output
#The histogram created: (array([1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1], dtype=int64), array([ 1. , 2.95, 4.9 , 6.85, 8.8 , 10.75, 12.7 , 14.65, 16.6 , 18.55, 20.5 , 22.45, 24.4 , 26.35, 28.3 , 30.25, 32.2 , 34.15, 36.1 , 38.05, 40. ]))</p><p>
Example
在這個例子中,我們透過指定bins和要使用的資料範圍來建立一個直方圖。以下程式碼可以作為參考。
import numpy as np arr = np.array([[20,20,25],[40,35,23],[34,22,1]]) hist = np.histogram(arr,bins = 20, range = (1,10)) print("The histogram created:", hist)
Output
#The histogram created: (array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0], dtype=int64), array([ 1. , 1.45, 1.9 , 2.35, 2.8 , 3.25, 3.7 ,4.15, 4.6 , 5.05, 5.5 , 5.95, 6.4 , 6.85, 7.3 , 7.75, 8.2 , 8.65, 9.1 , 9.55, 10. ]))
以上是使用Python中的NumPy計算一組資料的直方圖的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Python在遊戲和GUI開發中表現出色。 1)遊戲開發使用Pygame,提供繪圖、音頻等功能,適合創建2D遊戲。 2)GUI開發可選擇Tkinter或PyQt,Tkinter簡單易用,PyQt功能豐富,適合專業開發。

Python适合数据科学、Web开发和自动化任务,而C 适用于系统编程、游戏开发和嵌入式系统。Python以简洁和强大的生态系统著称,C 则以高性能和底层控制能力闻名。

2小時內可以學會Python的基本編程概念和技能。 1.學習變量和數據類型,2.掌握控制流(條件語句和循環),3.理解函數的定義和使用,4.通過簡單示例和代碼片段快速上手Python編程。

Python在web開發、數據科學、機器學習、自動化和腳本編寫等領域有廣泛應用。 1)在web開發中,Django和Flask框架簡化了開發過程。 2)數據科學和機器學習領域,NumPy、Pandas、Scikit-learn和TensorFlow庫提供了強大支持。 3)自動化和腳本編寫方面,Python適用於自動化測試和系統管理等任務。

兩小時內可以學到Python的基礎知識。 1.學習變量和數據類型,2.掌握控制結構如if語句和循環,3.了解函數的定義和使用。這些將幫助你開始編寫簡單的Python程序。

如何在10小時內教計算機小白編程基礎?如果你只有10個小時來教計算機小白一些編程知識,你會選擇教些什麼�...

使用FiddlerEverywhere進行中間人讀取時如何避免被檢測到當你使用FiddlerEverywhere...

Python3.6環境下加載Pickle文件報錯:ModuleNotFoundError:Nomodulenamed...


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

WebStorm Mac版
好用的JavaScript開發工具

SublimeText3漢化版
中文版,非常好用

Dreamweaver Mac版
視覺化網頁開發工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Atom編輯器mac版下載
最受歡迎的的開源編輯器