You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider a one-dimensional array Z, build a two-dimensional array whose first row is (Z[0],Z[1],Z[2]) and each subsequent row is shifted by 1 (last row should be (Z[-3],Z[-2],Z[-1]) (★★★)
1034
1042
1035
1043
< h76
1036
-
hint: from numpy.lib import stride_tricks
1044
+
hint: from numpy.lib import stride_tricks, from numpy.lib.stride_tricks import sliding_window_view (np>=1.20.0)
1037
1045
1038
1046
< a76
1039
1047
# Author: Joe Kington / Erik Rigtorp
@@ -1046,6 +1054,11 @@ def rolling(a, window):
1046
1054
Z = rolling(np.arange(10), 3)
1047
1055
print(Z)
1048
1056
1057
+
# Author: Jeff Luo (@Jeff1999)
1058
+
1059
+
Z = np.arange(10)
1060
+
print(sliding_window_view(Z, window_shape=3))
1061
+
1049
1062
< q77
1050
1063
How to negate a boolean, or to change the sign of a float inplace? (★★★)
1051
1064
@@ -1135,7 +1148,7 @@ print(R)
1135
1148
Consider an array Z = [1,2,3,4,5,6,7,8,9,10,11,12,13,14], how to generate an array R = [[1,2,3,4], [2,3,4,5], [3,4,5,6], ..., [11,12,13,14]]? (★★★)
1136
1149
1137
1150
< h81
1138
-
hint: stride_tricks.as_strided
1151
+
hint: stride_tricks.as_strided, from numpy.lib.stride_tricks import sliding_window_view (np>=1.20.0)
1139
1152
1140
1153
< a81
1141
1154
# Author: Stefan van der Walt
@@ -1144,6 +1157,11 @@ Z = np.arange(1,15,dtype=np.uint32)
0 commit comments