相关疑难解决方法(0)

在numpy中转换一组数字,以便将每个数字转换为一些小于它的其他数字

考虑一组数字:

In [8]: import numpy as np

In [9]: x = np.array([np.random.random() for i in range(10)])

In [10]: x
Out[10]: 
array([ 0.62594394,  0.03255799,  0.7768568 ,  0.03050498,  0.01951657,
        0.04767246,  0.68038553,  0.60036203,  0.3617409 ,  0.80294355])
Run Code Online (Sandbox Code Playgroud)

现在,我想这组变换成另一组y以下列方式:每个元素ix,相应的元素jy将其他元素的数量在x这不到i.例如,上面给出的内容x如下:

In [25]: y
Out[25]: array([ 6.,  2.,  8.,  1.,  0.,  3.,  7.,  5.,  4.,  9.])
Run Code Online (Sandbox Code Playgroud)

现在,我可以使用简单的python循环来做到这一点:

In [16]: for i in range(len(x)):
    ...:     tot = 0
    ...:     for j in …
Run Code Online (Sandbox Code Playgroud)

python numpy python-3.x

8
推荐指数
2
解决办法
210
查看次数

获取每2d数组的累积计数

我有一般数据,例如字符串:

np.random.seed(343)

arr = np.sort(np.random.randint(5, size=(10, 10)), axis=1).astype(str)
print (arr)
[['0' '1' '1' '2' '2' '3' '3' '4' '4' '4']
 ['1' '2' '2' '2' '3' '3' '3' '4' '4' '4']
 ['0' '2' '2' '2' '2' '3' '3' '4' '4' '4']
 ['0' '1' '2' '2' '3' '3' '3' '4' '4' '4']
 ['0' '1' '1' '1' '2' '2' '2' '2' '4' '4']
 ['0' '0' '1' '1' '2' '3' '3' '3' '4' '4']
 ['0' '0' '2' '2' '2' '2' '2' '2' '3' '4'] …
Run Code Online (Sandbox Code Playgroud)

python arrays counter numpy cumulative-sum

7
推荐指数
2
解决办法
264
查看次数

标签 统计

numpy ×2

python ×2

arrays ×1

counter ×1

cumulative-sum ×1

python-3.x ×1