我正在将Matlab脚本移植到Python。以下是摘录:
%// Create a list of unique trade dates
DateList = unique(AllData(:,1));
%// Loop through the dates
for DateIndex = 1:size(DateList,1)
CalibrationDate = DateList(DateIndex);
%// Extract the data for a single cablibration date (but all expiries)
SubsetIndice
我在Python中有一个非常大的二维数组,使用numpy库。我希望有效地遍历每一列,并检查每一次元素是否与0不同,以便在每一列中计算它们的数目。
假设我有下面的矩阵。
M = array([[1,2], [3,4]])
下面的代码使我们能够高效地遍历每一行(当然,这不是我打算做的!):
for row_idx, row in enumerate(M):
print "row_idx", row_idx, "row", row
for col_idx, element in enumerate(row):
print "c