使用numpy.split后删除子数组

时间:2016-10-19 23:20:43

标签: python numpy

Title有点说,我在尝试使用numpy.split后制作两个新的矩阵,所以:

#A is some mxn matrix
numfolds=5
folds = numpy.split(A,numfolds)
#now folds is 5 equalish subarrays which can be called out
#subarray1 is the second fold (the second fifth of A along axis=0 by default)
subarray1 = folds[2]
#numpy.delete does not get rid of the second subarray in A
arrayWithoutSubArray1 = numpy.concatenate(numpy.delete(folds[2]))

在这个例子中,如何制作一个矩阵,它只是A中的一个子阵列。我宁愿不使用循环。提前谢谢。

1 个答案:

答案 0 :(得分:0)

(代表OP发布)。

解决方案是在连接和索引之外进行正确的删除。

#A is some mxn matrix
numfolds=5
folds = numpy.split(A,numfolds)
#now folds is 5 equalish subarrays which can be called out
#subarray1 is the second fold (the second fifth of A along axis=0 by default)
subarray1 = folds[2]
#numpy.delete does not get rid of the second subarray in A
arrayWithoutSubArray1 = numpy.delete(folds,2,0)
arrayWithoutSubArray1 = numpy.concatenate(arrayWithoutSubArray1)