相关疑难解决方法(0)

Numpy:通过用零填充空元素来修复具有不同长度行的数组

我正在寻找的功能看起来像这样:

data = np.array([[1, 2, 3, 4],
                 [2, 3, 1],
                 [5, 5, 5, 5],
                 [1, 1]])

result = fix(data)
print result

[[ 1.  2.  3.  4.]
 [ 2.  3.  1.  0.]
 [ 5.  5.  5.  5.]
 [ 1.  1.  0.  0.]]
Run Code Online (Sandbox Code Playgroud)

我正在使用的这些数据阵列非常大,所以我真的很感激最有效的解决方案.

编辑:数据作为python列表列表从磁盘读入.

python arrays performance numpy python-2.7

28
推荐指数
3
解决办法
1万
查看次数

有numpy argsort返回一个2d索引数组?

如果我们有一个1d数组

arr = np.random.randint(7, size=(5))
# [3 1 4 6 2]
print np.argsort(arr)
# [1 4 0 2 3] <= The indices in the sorted order    
Run Code Online (Sandbox Code Playgroud)

如果我们有一个2d数组

arr = np.random.randint(7, size=(3, 3))
# [[5 2 4]
# [3 3 3]
# [6 1 2]]
print np.argsort(arr)
# [[1 2 0]
# [0 1 2]
# [1 2 0]] <= It sorts each row
Run Code Online (Sandbox Code Playgroud)

我需要的是2d索引,它将整个矩阵排序.像这样的东西:

# [[2 1] => 1
# [0 1] => 2
# [2 2] => 2
# …
Run Code Online (Sandbox Code Playgroud)

python arrays numpy

11
推荐指数
2
解决办法
8098
查看次数

标签 统计

arrays ×2

numpy ×2

python ×2

performance ×1

python-2.7 ×1