我有这个numpy数组:
sample=
[[0.8 0.2 0.7 0.1]
[0.7 0.5 0.5 0.0]
[0.7 0.5 0.5 0.1]
[0.7 0.5 0.3 0.3]
[0.9 0.6 0.2 0.1]
[0.8 0.6 0.5 0.0]]
我想根据rows(6)拆分它,并将这些值放入不同的numpy数组中。 例如:
sample_row_1 = [0.8 0.2 0.7 0.1]
sample_row_2 = [0.7 0.5 0.5 0.0]
sample_row_3 = [0.7 0.5 0.5 0.1]
sample_row_4 = [0.7 0.5 0.3 0.3]
sample_row_5 = [0.9 0.6 0.2 0.1]
sample_row_6 = [0.8 0.6 0.5 0.0]
答案 0 :(得分:0)
应该有一个令人信服的理由,说明通过A[i]
进行基本数组索引不足,而您 需要提取到多个变量。
并且,如果有令人信服的原因,则不应定义数量可变的变量。请改用字典:
import numpy as np
A = np.arange(16).reshape((4, 4))
arrs = {i: A[i] for i in range(A.shape[0])}
print(arrs)
{0: array([0, 1, 2, 3]),
1: array([4, 5, 6, 7]),
2: array([ 8, 9, 10, 11]),
3: array([12, 13, 14, 15])}
答案 1 :(得分:0)
或将它们放在ndarray列表中:
import numpy as np
A = np.arange(16).reshape((4, 4))
y = [a for a in A]
print(y)
# and access by index
print(y[0])