np.unique() से Unique Values
np.unique() एक array में distinct values ढूंढता है, sorted, और इन्हें count भी कर सकता है।
In this page:
Syntax
values = np.unique(arr)
values, counts = np.unique(arr, return_counts=True)
np.unique()
np.unique sorted unique elements return करता है। return_counts=True के साथ आपको यह भी मिलता है कि हर एक कितनी बार appear होता है, और return_inverse हर original element को इसके unique index में map करता है। यह multi-dimensional input flatten करता है जब तक आप एक axis न दें।
Note:
return_counts के साथ unique एक fast frequency table है।
उदाहरण: np.unique()
import numpy as np
a = np.array([3, 1, 2, 3, 3, 1])
vals, counts = np.unique(a, return_counts=True)
print(vals)
print(counts)
# Output:
# [1 2 3]
# [2 1 3]
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- यह उम्मीद करना कि original order preserve होगा
- यह भूल जाना कि multi-dimensional input flatten होता है
- ज़रूरत पड़ने पर counts न माँगना
चैप्टर सारांश
- unique sorted distinct values return करता है
- return_counts frequencies देता है
- Original order नहीं रखा जाता
- axis न दिए जाने पर flatten करता है
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: