目录
- 1. 查看numpy版本
- 2. 创建一维数组
- 3. 创建布尔数组
- 4. 从一维数组按照条件过滤数据
- 5. 一维数组按照条件修改数据
- 6. 保留原始数据进行修改
- 7. 重塑数组
- 8.垂直堆叠数组
- 9.垂直堆叠数组
- 10.自定义序列
- 11.获取数组的公共元素
- 12.一个数组去掉另一个数组中的元素
- 13.一个数组去掉另一个数组中的元素
- 14.提取给定范围内的所有数子
- 15.标量函数在python数组上运行
- 16. 数组的行排序和列排序
- 17. 随机数
- 17. 格式化输出
- 17. 导入含有数字和文本的数据,并保持数据完整性
- 17. 一维元组数组中提取特定的列
- 18. 一维元组转化为二维数组
- 18. 计算平均数,中位数,标准差
- 18. 归一化数组
- 18. 计算softmax值
- 18.数组的百分位的值
- 20.在数组的随机位置更新值
- 20.查找缺失值
- 20.数据筛选
- 20.两列之间的关联性
- 20.查找数组是否有缺失值/替换空值
- 20.找出唯一值极其数量
- 20.将数值转化为文本
- 20.数组创建新列
- 20.概率抽样
- 20.第二长的物种最大价值
- 20.二维数组排序
- 20.返回数组中最大的值
- 20.用边界值替换区间外值
- 20.数组中获取n个值的位置
- 20.计算唯一值在每一行出现的次数
1. 查看numpy版本
使用np.__version__输出numpy版本
import numpy as np
print(np.__version__)
2. 创建一维数组
使用array(list)创建
arr = np.array([1,2,3,4,5])
print(arr)
3. 创建布尔数组
np.full用于创建一个值相同的多位矩阵,所有元素值都相同,数据类型不限
arr = np.full((3,3), True)
print(arr)
输出
>> [[ True True True]
[ True True True]
[ True True True]]
4. 从一维数组按照条件过滤数据
arr = np.array([1,2,3,4,5])
arr1 = arr[arr%2 == 1]
arr2 = arr[arr > 2]
print(arr1)
print(arr2)
输出
>> [1 3 5]
[3 4 5]
5. 一维数组按照条件修改数据
arr = np.array([1,2,3,4,5])
arr[arr%2 == 1] = -1
print(arr)
输出
>> [-1 2 -1 4 -1]
6. 保留原始数据进行修改
arr = np.array([1,2,3,4,5])
arr1 = np.where(arr%2 == 1,-1, arr)
print(arr1)
输出
>> [-1 2 -1 4 -1]
7. 重塑数组
使用arr.reshape方法重塑数组, 返回堆原数组的拷贝,不改变当前数组
arr = np.arange(12)
arr1 = arr.reshape(2,3,2)
# 最后一个维度可以不写,记成-1
# arr1 = arr.reshape(2,3,-1)
print(arr1)
print(arr)
输出
>> [[[ 0 1]
[ 2 3]
[ 4 5]]
[[ 6 7]
[ 8 9]
[10 11]]]
>> [ 0 1 2 3 4 5 6 7 8 9 10 11]
8.垂直堆叠数组
np.concatenate
np.vstack
a = np.arange(10).reshape(2,-1)
b = np.repeat(1, 10).reshape(2,-1)
c1 = np.concatenate([a,b],axis=0)
c2 = np.vstack((a,b) )
print(c1)
print(c2)
输出
>>>[[0 1 2 3 4]
[5 6 7 8 9]
[1 1 1 1 1]
[1 1 1 1 1]]
>>>[[0 1 2 3 4]
[5 6 7 8 9]
[1 1 1 1 1]
[1 1 1 1 1]]
9.垂直堆叠数组
np.concatenate
np.vstack
a = np.arange(10).reshape(2,-1)
b = np.repeat(1, 10).reshape(2,-1)
c1 = np.concatenate([a,b],axis=1)
c2 = np.hstack(a,b)
print(c1)
print(c2)
10.自定义序列
arr1 = arr1 = np.array([1, 2, 3, 4, 5])
# 将数组进行重复
arr2 = np.tile(arr1,3)
# 每个元素重复,再拼接到一起
arr3 = np.repeat(arr1,3)
# 将两个数组水平连在一起
arr4 = np.r_[arr2, arr3]
print(arr1)
print(arr2)
print(arr3)
print(arr4)
>>>[1 2 3 4 5]
>>>[1 2 3 4 5 1 2 3 4 5 1 2 3 4 5]
>>>[1 1 1 2 2 2 3 3 3 4 4 4 5 5 5]
>>>[1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5]
11.获取数组的公共元素
np.intersect1d 求两个数组的交集,如果共同元素在两个数组中出现了多次,那么结果集中夜只显示一次,换言之,得到的结果是一个集合,不会有重复元素。
arr1 = np.array([1,2,3,4,5,6,7,8,9])
arr2 = np.array([1,4,7])
res = np.intersect(arr1, arr2)
print(res)
输出
>>>[1, 4, 7]
12.一个数组去掉另一个数组中的元素
np.setdiff1d求两个数组的交集,如果共同元素在两个数组中出现了多次,那么结果集中夜只显示一次,换言之,得到的结果是一个集合,不会有重复元素。
arr1 = np.array([1,2,3,4,5,6,7,8,9])
arr2 = np.array([1,4,7])
res = np.setdiff1d(arr1, arr2)
print(res)
输出
>>>[2 3 5 6 8 9]
13.一个数组去掉另一个数组中的元素
使用where方法,要求数组长度必须相等,返回值的索引值是参考第一个数组的,也就是说,返回的是重复元素在第一个数组中的位置。
arr1 = np.array([1,2,3,2,3,4,3,4,5,6])
arr2 = np.array([7,2,10,2,7,4,9,4,9,8])
res = np.where(arr1, arr2)
print(res)
输出
>>>(array([1, 3, 5, 7], dtype=int64),)
14.提取给定范围内的所有数子
方法1:借助np.arrage生成连续数字,借助np.where过滤数据
arr1 = np.arange(15)、
print(arr1)
res = np.where((arr1>5) & (arr1 <11))
print(res)
输出
>>> array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])
>>>> (array([ 6, 7, 8, 9, 10], dtype=int64),)
方法2:借助np.arrage生成连续数字,arange函数可以指定开始和结束数字及步长, 输出的数组中,含开始数字,不含结束数字
arr1 = np.arange(10,20,2)
print(arr1)
输出
>>> [10 12 14 16 18]
方法3:借助python内置函数range实现,
15.标量函数在python数组上运行
np.vectorize(func)可以实现
传入的函数可以是内置函数、自定义函数和lamda函数
def myMax(a,b):
return a if a>b else b
vecMax = np.vectorize(myMax)
# 内置函数
# vecMax = np.vectorize(max)
# lamda函数
# vecMax = np.vectorize(lambda x,y:x if x>= y else y)
arr1 = np.array([1,5,3])
arr2 = np.array([2,4,6])
res = vecMax(arr1, arr2)
print(res)
输出
>>>[2 5 6]
16. 数组的行排序和列排序
对于多位数组mat,使用mat[x,y,z]进行索引,索引可以为标量数字,也可以我数组。对索引值进行排序,也就实现了对多位数组的行列排序。
mat = np.arange(9).reshape(3,3)
# 输出两行
arr1 = mat[[1,2],:]
# 前两行调换顺序
arr2 = mat[[1,0,2],:]
# 调换前两列的顺序
arr3 = mat[:, [1,0,2]]
# 列逆序输出
arr4 = mat[:, ::-1]
print(arr1)
print(arr2)
print(arr3)
print(arr4)
输出为
>>>[[3 4 5]
[6 7 8]]
>>>[[1 0 2]
[4 3 5]
[7 6 8]]
>>>[[1 0 2]
[4 3 5]
[7 6 8]]
>>>[[2 1 0]
[5 4 3]
[8 7 6]]
17. 随机数
使用np.random.random(size)创建一个0到1的随机浮点数的数组,大小由元组size制定
使用np.random.randint(low, high, size)创建low和high之间的数组,大小由size指定
生成两个数之间的浮点数,可以使用两个函数加起来来实现.
也可以用np.
arr1 = np.random.randint(6, 10, size=(5,3))+np.random.random((5,3))
print(arr1)
arr2 = np.random.uniform(6,10,size=(5,3))
print(arr2)
输出
>>>[[7.18733986, 9.74966754, 6.64476223],
[9.30852401, 9.32758993, 6.08517657],
[7.18820005, 9.46282236, 7.30198262],
[7.61703484, 7.11062727, 9.65965275],
[8.56002979, 7.65555522, 9.797933 ]]
>>>[[6.73951761 7.39977839 8.24507311]
[6.23727964 8.23869382 6.9117679 ]
[6.35928561 8.2323571 8.42812538]
[6.5990485 9.94243376 7.41793685]
[7.07269307 8.44199938 9.77515841]]
17. 格式化输出
设置浮点数的输出小数位
np.set_printoptions(precision=4)
使用科学计数法
np.set_printoptions(supress=False)
打印完整数组
np.set_printoptions(threshhod=6)#元素超过6个,中间元素会显示省略号
np.set_printoptions(threshhod=np.nan)#打印完整数组
17. 导入含有数字和文本的数据,并保持数据完整性
由于我们想保留物种,一个文本字段,我已经把dtype设置为object。设置dtype = None,则会返回一维元组数组。
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris = np.genfromtxt(url, delimiter=',', dtype='object')
print(iris)
输出
>>>[[b'5.1' b'3.5' b'1.4' b'0.2' b'Iris-setosa']
[b'4.9' b'3.0' b'1.4' b'0.2' b'Iris-setosa']
[b'4.7' b'3.2' b'1.3' b'0.2' b'Iris-setosa']]
17. 一维元组数组中提取特定的列
借助于python列表生成式来实现
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris = np.genfromtxt(url, delimiter=',', dtype=None)
print(iris.shape)
species = np.array([row[4] for row in iris])
print(species[:5])
输出
>>>(150,)
>>>[b'Iris-setosa' b'Iris-setosa' b'Iris-setosa' b'Iris-setosa'
b'Iris-setosa']
18. 一维元组转化为二维数组
方法1:将每行通过list函数,转换为数组
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris = np.genfromtxt(url, delimiter=',', dtype=None)
print(iris.shape)
iris_2d = np.array([row.tolist()[0:4] for row in iris])
print(iris_2d[0:5])
输出:
# 注意,这里一行也只有一个列
>>>(150,)
>>> [[5.1 3.5 1.4 0.2]
[4.9 3. 1.4 0.2]
[4.7 3.2 1.3 0.2]
[4.6 3.1 1.5 0.2]
[5. 3.6 1.4 0.2]]
方法2:指定数据类型后,读进来就是二维数组,类型不匹配的内容,显示nan
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris = np.genfromtxt(url, delimiter=',', dtype="float",usecols=[0,
...: 1,2,3])
print(iris.shape)
iris_2d = np.array([row.tolist()[0:4] for row in iris])
print(iris_2d[0:5])
输出
[[5.1 3.5 1.4 0.2]
[4.9 3. 1.4 0.2]
[4.7 3.2 1.3 0.2]
[4.6 3.1 1.5 0.2]
[5. 3.6 1.4 0.2]]
18. 计算平均数,中位数,标准差
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
sepallength = np.genfromtxt(url, delimiter=',', dtype="float",usecols=[0])
mu, med, sd = np.mean(sepallength ),np.median(sepallength ),np.std(sepallength )
print(mu, med, sd)
输出
5.843333333333334 5.8 0.8253012917851409
18. 归一化数组
使用max()和min()方法求出数组的最小值
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
sepallength = np.genfromtxt(url, delimiter=',', dtype="float",usecols=[0])
S_max = sepallength.max();
S_min = sepallength.min();
def norm(In, minData, maxData):
return (In-minData)/(maxData-minData)
norm_func = np.vectorize(norm)
out = norm_func(sepallength, S_min , S_max )
print(out[:5])
输出
[0.22222222 0.16666667 0.11111111 0.08333333 0.19444444]
18. 计算softmax值
softmax值的计算方式如下所示,将输入转化为一个0到1的值,结果表现为值越大,越容易突出。
S
i
=
e
i
∑
i
=
1
n
e
i
S_i = \frac{e^i}{\sum_{i=1}^{n}e^i}
Si=∑i=1neiei
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
sepallength = np.genfromtxt(url, delimiter=',', dtype="float",usecols=[0])
def softMax(mat):
return np.exp(mat)/np.exp(mat).sum(axis=0)
res = softMax(sepallength )
print(res)
输出
>>>[0.00221959 0.00181724 0.00148783 0.00134625 0.00200836]
18.数组的百分位的值
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
sepallength = np.genfromtxt(url, delimiter=',', dtype="float",usecols=[0])
res = np.percentile(sepallength,[5,30,40,50,95])
print(res)
输出
>>>[4.6 5.27 5.6 5.8 7.255]
20.在数组的随机位置更新值
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris= np.genfromtxt(url, delimiter=',', dtype="object")
i,j = np.where(iris)
np.random.seed(100)
rand_x = np.random.random(i,20)
rand_y = np.random.random(j,20)
iris[rand_x, rand_y] = np.nan
# 方法2:使用randint来实现
# 初始化随机数种子,每次执行初始化后,执行同一个随机函数,结果相同
np.random.seed(100)
rand_x = np.random.randint(i,size=20)
rand_y = np.random.randint(j,size=20)
iris[rand_x, rand_y] = np.nan
20.查找缺失值
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris= np.genfromtxt(url, delimiter=',', dtype="float", usecols=[0,1,2,3])
m,n = np.shape(iris)
# 制造缺失值
rand_x = np.random.randint(m,size=(20,))
rand_y = np.random.randint(n,size=(20,))
iris[rand_x, rand_y] = np.nan
# 缺失值的数量
number = np.isnan(iris[:,0 ]).sum()
pos = np.where(np.isnan(iris[:,0 ]))
print(number)
print(pos)
输出
>>> 3
>>> (array([ 2, 82, 113], dtype=int64),)
20.数据筛选
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris= np.genfromtxt(url, delimiter=',', dtype="float", usecols=[0,1,2,3])
#逻辑连接符号要加括号
cond = (iris[:,2]>1.5) & (iris[:,0]<5)
print(iris[cond])
输出
array([[4.8, 3.4, 1.6, 0.2],
[4.8, 3.4, 1.9, 0.2],
[4.7, 3.2, 1.6, 0.2],
[4.8, 3.1, 1.6, 0.2],
[4.9, 2.4, 3.3, 1. ],
[4.9, 2.5, 4.5, 1.7]])
20.两列之间的关联性
计算皮尔逊积矩相关系数
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris= np.genfromtxt(url, delimiter=',', dtype="float", usecols=[0,1,2,3])
# 计算两个数组的相关性
res = np.corrcoef(iris[:,0], iris[:,2])
print(res)
# 计算多个数组的相关性
x = np.vstack((iris[:,0], iris[:,2],iris[:,3]))
res = np.corrcoef(iris[:,0], iris[:,2])
print(res)
#
from scipy.stats.stats import pearsonr
corr, p_value = pearsonr(iris[:,0], iris[:,2])
print(corr)
print(p_value)
输出
>>> [[1. 0.87175416]
[0.87175416 1. ]]
>>> [[1. , 0.87175416, 0.81795363],
[0.87175416, 1. , 0.9627571 ],
[0.81795363, 0.9627571 , 1. ]]
>>> 0.8717541573048713
20.查找数组是否有缺失值/替换空值
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris= np.genfromtxt(url, delimiter=',', dtype="float", usecols=[0,1,2,3])
m,n = np.shape(iris)
# 制造缺失值
rand_x = np.random.randint(m,size=(20,))
rand_y = np.random.randint(n,size=(20,))
iris[rand_x, rand_y] = np.nan
isEmpty = np.isnan(iris).any()
print(isEmpty)
iris[np.isnan(iris)] = 0
20.找出唯一值极其数量
使用np.unique()函数
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris= np.genfromtxt(url, delimiter=',', dtype="object")
species = np.array([row.tolist() for row in iris])
np.unique(species[:,-1], return_counts=True)
20.将数值转化为文本
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris= np.genfromtxt(url, delimiter=',', dtype="object")
names = ("sepallength","sepalwidth", "petallength", "petalwidth")
# 数据进行分割,用1,2,3,4表示数据区间
petal_length_bin = np.digitize(iris[:,2].astype("float"),[0,3,5,10])
label_map={1:"small", 2:"medium", 3:"large", 4:np.nan}
# 重新输出
petal_length_cat = [label_map[x] for x in petal_length_bin ]
print(petal_length_cat)
20.数组创建新列
使用np.newaxis索引列来创建新数据,使用vstack添加一列
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris= np.genfromtxt(url, delimiter=',', dtype="object")
names = ("sepallength","sepalwidth", "petallength", "petalwidth")
sepallength = iris[:,0].astype("float")
petallength = iris[:,2].astype("float")
volume = np.pi*sepallength*petallength**2/3
volume = volume[:, np.newaxis]
out = np.hstack([iris, volume])
print(out[:5,:])
输出
>>>[[b'5.1' b'3.5' b'1.4' b'0.2' b'Iris-setosa' 10.467786721761188]
[b'4.9' b'3.0' b'1.4' b'0.2' b'Iris-setosa' 10.057285281692124]
[b'4.7' b'3.2' b'1.3' b'0.2' b'Iris-setosa' 8.317890149154577]
[b'4.6' b'3.1' b'1.5' b'0.2' b'Iris-setosa' 10.838494654884785]
[b'5.0' b'3.6' b'1.4' b'0.2' b'Iris-setosa' 10.262536001726657]]
20.概率抽样
调整不同类别的采样频率使用choice函数实现
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris= np.genfromtxt(url, delimiter=',', dtype="object")
m,n = np.shape(iris)
species = iris[:,4]
category = np.array(["Iris-setosa", "Iris-setversicolor", "Iris-virginica"])
# 这个例子中的采样结果和原始数据之间没有多大关系
# 对每个类别下产生随机数的频率比进行调整
species_out = np.random.choice(category, m, p=[0.5, 0.25, 0.25])
print(np.unique(species_out, return_counts=True))
输出
>>>(array(['Iris-setosa', 'Iris-setversicolor', 'Iris-virginica'],
dtype='<U18'), array([80, 32, 38], dtype=int64))
方法二
np.searchsorted()完成数据顺序插入,并返回插入的数据在目标数组中的位置。
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris= np.genfromtxt(url, delimiter=',', dtype="object")
m,n = np.shape(iris)
probs = np.r_[np.linspace(0,0.5,num=50), np.linspace(0.501, 0.75,num=50), np.linspace(0.751,1,num=50) ]
probs = np.r_[np.linspace(0,0.5,num=50), np.linspace(0.501, 0.75,n
...: um=50), np.linspace(0.751,1,num=50)
...: ]
index = np.searchsorted(probs, np.random.random(150))
species_out = species[index]
print(np.unique(species_out, return_counts=True))
输出
(array([b'Iris-setosa', b'Iris-versicolor', b'Iris-virginica'],
dtype=object), array([80, 41, 29], dtype=int64))
20.第二长的物种最大价值
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris= np.genfromtxt(url, delimiter=',', dtype="object")
m,n = np.shape(iris)
species = iris[:,4]
category = np.array(["Iris-setosa", "Iris-setversicolor", "Iris-virginica"])
petal_len_setosa = iris[iris[:,4] == b"Iris-setosa", 2].astype("float")
# 将值转化为浮点数之后,进行排序,取倒数第二个
res = np.unique(np.sort(petal_len_setosa))[-2]
print(res)
输出
>>>1.7
20.二维数组排序
使用np.sort()对数组进行排序
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris= np.genfromtxt(url, delimiter=',', dtype="object")
iris[iris[:,0].argsort()][0:20]
输出
[[b'4.3', b'3.0', b'1.1', b'0.1', b'Iris-setosa'],
[b'4.4', b'3.2', b'1.3', b'0.2', b'Iris-setosa'],
[b'4.4', b'3.0', b'1.3', b'0.2', b'Iris-setosa'],
[b'4.4', b'2.9', b'1.4', b'0.2', b'Iris-setosa'],
[b'4.5', b'2.3', b'1.3', b'0.3', b'Iris-setosa'],
[b'4.6', b'3.6', b'1.0', b'0.2', b'Iris-setosa'],
[b'4.6', b'3.1', b'1.5', b'0.2', b'Iris-setosa'],
[b'4.6', b'3.4', b'1.4', b'0.3', b'Iris-setosa'],
[b'4.6', b'3.2', b'1.4', b'0.2', b'Iris-setosa'],
[b'4.7', b'3.2', b'1.3', b'0.2', b'Iris-setosa'],
[b'4.7', b'3.2', b'1.6', b'0.2', b'Iris-setosa'],
[b'4.8', b'3.0', b'1.4', b'0.1', b'Iris-setosa'],
[b'4.8', b'3.0', b'1.4', b'0.3', b'Iris-setosa'],
[b'4.8', b'3.4', b'1.9', b'0.2', b'Iris-setosa'],
[b'4.8', b'3.4', b'1.6', b'0.2', b'Iris-setosa'],
[b'4.8', b'3.1', b'1.6', b'0.2', b'Iris-setosa'],
[b'4.9', b'2.4', b'3.3', b'1.0', b'Iris-versicolor'],
[b'4.9', b'2.5', b'4.5', b'1.7', b'Iris-virginica'],
[b'4.9', b'3.1', b'1.5', b'0.1', b'Iris-setosa'],
[b'4.9', b'3.1', b'1.5', b'0.1', b'Iris-setosa']], dtype=object)
20.返回数组中最大的值
np.argmax()返回数组中的最大值
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
iris= np.genfromtxt(url, delimiter=',', dtype="object")
np.argmax(iris[:,3].astype("float")>1)
20.用边界值替换区间外值
np.random.seed(100)
arr1 = np.random.uniform(1,50,20)
res = numpy.clip(arr1 , a_min=10, a_max=30)
print(res)
# 方法2
np.where(arr1<10,10,np.where(arr1>30,30,arr1))
print(res)
输出
>>> [27.62684215, 14.64009987, 21.80136195, 30. , 10. ,
10. , 30. , 30. , 10. , 29.17957314,
30. , 11.25090398, 10.08108276, 10. , 11.76517714,
30. , 30. , 10. , 30. , 14.42961361]
20.数组中获取n个值的位置
arr1.argsort()返回排序后的索引值
np.random.seed(100)
arr1 = np.random.uniform(1,50,20)
print(arr1[arr1.argsort()][-5:])
输出
[40.99501269 41.466785 42.39403048 44.67477576 48.95256545]
20.计算唯一值在每一行出现的次数
np.random.seed(100)
arr1 = np.random.randint(1,11,size=(6,10))
def counts_of_all_values_rowwise(arr2d):
num_counts_array = [np.unique(row, return_counts=True) for row in arr1 ]
return([])