2024-04-20 09:12:07 发布
网友
我想生成一个向量(用作索引),如以下在Matlab中生成的向量:
idx = [1:60,71:120,181:240]' % it is used as indices in A = B(idx,:,:)
如何用Python重写上面的代码
只需使用np.r_:
np.r_
import numpy as np idx = np.r_[1:60,61:120,181:240]
收益率:
[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239]
请注意,Python中的范围不包括与Matlab相反的上限,以及Python从0索引,而Matlab从1索引的事实。你知道吗
只需使用
np.r_
:收益率:
请注意,Python中的范围不包括与Matlab相反的上限,以及Python从0索引,而Matlab从1索引的事实。你知道吗
相关问题 更多 >
编程相关推荐