Số lượng tần số đa chiều, tức là đếm mảng.
>>> print[color_array ]
array[[[255, 128, 128],
[255, 128, 128],
[255, 128, 128],
...,
[255, 128, 128],
[255, 128, 128],
[255, 128, 128]], dtype=uint8]
>>> np.unique[color_array,return_counts=True,axis=0]
[array[[[ 60, 151, 161],
[ 60, 155, 162],
[ 60, 159, 163],
[ 61, 143, 162],
[ 61, 147, 162],
[ 61, 162, 163],
[ 62, 166, 164],
[ 63, 137, 162],
[ 63, 169, 164],
array[[ 1, 2, 2, 1, 4, 1, 1, 2,
3, 1, 1, 1, 2, 5, 2, 2,
898, 1, 1,
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọcnumpy.unique[] function to find the unique elements and it’s corresponding frequency in a numpy array.
Bàn luận numpy.unique[arr, return_counts=False]
Hãy cùng xem cách đếm tần số của các giá trị duy nhất trong mảng numpy. Thư viện Python sườn Numpy cung cấp chức năng Numpy.unique [] để tìm các yếu tố độc đáo và tần số tương ứng của nó trong một mảng numpy. Sorted unique elements of an array with their corresponding frequency counts NumPy array.
Cú pháp: numpy.unique [mảng, return_counts = false]
Trả về: Sắp xếp các phần tử duy nhất của một mảng với số lượng tần số tương ứng của chúng.
Python3
Bây giờ, hãy để xem các ví dụ:
Ví dụ 1:
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]5
10
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]0
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]8
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]0
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]1
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]4
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]5
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]8
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]0
The values and their frequency are: [[ 5 8 9 10 20] [ 1 2 1 2 2]]5
The values and their frequency are: [[ 5 8 9 10 20] [ 1 2 1 2 2]]6
import
numpy as np
ini_array
=
The values and their frequency are in transpose form: [[ 5 1] [ 8 2] [ 9 1] [10 2] [20 2]]5
The values and their frequency are in transpose form: [[ 5 1] [ 8 2] [ 9 1] [10 2] [20 2]]6
The values and their frequency are in transpose form: [[ 5 1] [ 8 2] [ 9 1] [10 2] [20 2]]7
The values and their frequency are in transpose form: [[ 5 1] [ 8 2] [ 9 1] [10 2] [20 2]]8
The values and their frequency are in transpose form: [[ 5 1] [ 8 2] [ 9 1] [10 2] [20 2]]9
import
0The values and their frequency are in transpose form: [[ 5 1] [ 8 2] [ 9 1] [10 2] [20 2]]5
The values and their frequency are in transpose form: [[ 5 1] [ 8 2] [ 9 1] [10 2] [20 2]]6
import
3Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]4
The values and their frequency are in transpose form: [[ 5 1] [ 8 2] [ 9 1] [10 2] [20 2]]9
import
6Output:
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]
The values and their frequency are:
[[ 5 8 9 10 20]
[ 1 2 1 2 2]]
7=
The values and their frequency are:
[[ 5 8 9 10 20]
[ 1 2 1 2 2]]
9
Python3
Bây giờ, hãy để xem các ví dụ:
Ví dụ 1:
numpy as np
810
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]0
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]8
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]0
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]1
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]4
numpy as np
8
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]8
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]0
The values and their frequency are: [[ 5 8 9 10 20] [ 1 2 1 2 2]]5
The values and their frequency are: [[ 5 8 9 10 20] [ 1 2 1 2 2]]6
import
numpy as np
ini_array
=
The values and their frequency are: [[ 5 8 9 10 20] [ 1 2 1 2 2]]7
=
The values and their frequency are: [[ 5 8 9 10 20] [ 1 2 1 2 2]]9
The values and their frequency are in transpose form: [[ 5 1] [ 8 2] [ 9 1] [10 2] [20 2]]5
The values and their frequency are in transpose form: [[ 5 1] [ 8 2] [ 9 1] [10 2] [20 2]]6
np.array[[
3Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]4
np.array[[
5np.array[[
6
Output:
The values and their frequency are: [[ 5 8 9 10 20] [ 1 2 1 2 2]]
The values and their frequency are in transpose form:
[[ 5 1]
[ 8 2]
[ 9 1]
[10 2]
[20 2]]
0The values and their frequency are in transpose form:
[[ 5 1]
[ 8 2]
[ 9 1]
[10 2]
[20 2]]
1=
The values and their frequency are in transpose form:
[[ 5 1]
[ 8 2]
[ 9 1]
[10 2]
[20 2]]
3The values and their frequency are in transpose form:
[[ 5 1]
[ 8 2]
[ 9 1]
[10 2]
[20 2]]
4
Python3
Bây giờ, hãy để xem các ví dụ:
Ví dụ 1:
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]5
10
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]0
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]8
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]0
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]1
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]4
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]5
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]8
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]0
The values and their frequency are: [[ 5 8 9 10 20] [ 1 2 1 2 2]]5
The values and their frequency are: [[ 5 8 9 10 20] [ 1 2 1 2 2]]6
import
numpy as np
ini_array
=
The values and their frequency are: [[ 5 8 9 10 20] [ 1 2 1 2 2]]7
=
The values and their frequency are: [[ 5 8 9 10 20] [ 1 2 1 2 2]]9
The values and their frequency are in transpose form: [[ 5 1] [ 8 2] [ 9 1] [10 2] [20 2]]5
The values and their frequency are in transpose form: [[ 5 1] [ 8 2] [ 9 1] [10 2] [20 2]]6
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]23
Unique Values: [ 5 8 9 10 20] Frequency Values: [1 2 1 2 2]4
np.array[[
5np.array[[
6
Output:
The values and their frequency are in transpose form: [[ 5 1] [ 8 2] [ 9 1] [10 2] [20 2]]