{"id":184787,"date":"2020-10-26T22:25:55","date_gmt":"2020-10-26T14:25:55","guid":{"rendered":"http:\/\/4563.org\/?p=184787"},"modified":"2020-10-26T22:25:55","modified_gmt":"2020-10-26T14:25:55","slug":"%e6%9c%89%e6%b2%a1%e6%9c%89-reset-%e7%9a%84-cumsum-%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=184787","title":{"rendered":"\u6709\u6ca1\u6709 reset \u7684 cumsum \u51fd\u6570"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6709\u6ca1\u6709 reset \u7684 cumsum \u51fd\u6570               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : admirez <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u6bd4\u5982\uff3b-1\uff0c-1\uff0c-1\uff0c1\uff0c1\uff0c1\uff0c1\uff0c-1\uff0c-1 \uff3d\u3002<\/p>\n<p>\u80fd\u53d8\u6210 -1\uff0c-2\uff0c-3\uff0c1\uff0c2\uff0c3\uff0c4\uff0c-1\uff0c-2<\/p>\n<p>\u6700\u597d\u662f\u9ad8\u6548\u7387\u7684      <\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3979906\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : necomancer <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             a = np.array([-1,-1,-1,1,1,1,1,-1,-1])<br \/>bounds = np.r_[0, np.argwhere(np.diff(a&gt;0, prepend=0)).ravel(), a.shape[0]]<br \/>np.concatenate([np.cumsum(a[i:j]) for i, j in zip(bounds[:-1], bounds[1:])])                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3979907\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : necomancer <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53ef\u80fd\u5feb\u4e00\u70b9\uff0c\u5c24\u5176\u662f 1\uff0c -1 \u4ea4\u9519\u5f88\u5389\u5bb3\u7684\u65f6\u5019<br \/>import pandas as pd<br \/>b = pd.Series(np.insert(a, np.argwhere(np.diff(a&gt;0, prepend=0)).ravel(), 0))<br \/>cum = b.cumsum()<br \/>cum = (cum -cum.where(b==0).ffill().fillna(0)).values<br \/>cum = cum[cum!=0]                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3979908\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : admirez <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @necomancer \u975e\u5e38\u611f\u8c22\uff0c\u6211\u8bd5\u8bd5\u770b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u6ca1\u6709 reset \u7684 cumsu&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/184787"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=184787"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/184787\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=184787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=184787"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=184787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}