{"version":"1.0","type":"rich","author_name":"atsuhiro-me","provider_name":"Hatena Blog","height":"190","provider_url":"https://hatena.blog","categories":["Python"],"published":"2023-12-18 00:43:50","url":"https://pc.atsuhiro-me.net/entry/2023/12/18/004350","image_url":null,"title":"numpy \u3067\u6307\u5b9a\u3057\u305f\u30c7\u30fc\u30bf\u3060\u3051\u3092\u5408\u8a08\u3059\u308b","description":"sum() \u95a2\u6570\u306e where \u3067\u6307\u5b9a\u3057\u307e\u3059\uff0e numpy.sum \u2014 NumPy v1.26 Manual import numpy as np a = np.array( [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ] ) b = np.array( [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], ] ) v = a.sum(where=b.astype(bool)) print(v) \u5b9f\u884c\u3059\u308b\u3068\uff0c1+6+11 = 18 \u304c\u5f97\u3089\u308c\u307e\u3059\uff0e\u30de\u30b9\u30af\u3057\u305f\u30c7\u30fc\u30bf\u3092\u51e6\u7406\u3059\u308b\u3068\u304d\u306b\u4fbf\u5229\u3067\u3059\uff0e","blog_title":"\u307f\u30fc\u306e\u307a\u30fc\u3058","author_url":"https://blog.hatena.ne.jp/atsuhiro-me/","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fpc.atsuhiro-me.net%2Fentry%2F2023%2F12%2F18%2F004350\" title=\"numpy \u3067\u6307\u5b9a\u3057\u305f\u30c7\u30fc\u30bf\u3060\u3051\u3092\u5408\u8a08\u3059\u308b - \u307f\u30fc\u306e\u307a\u30fc\u3058\" class=\"embed-card embed-blogcard\" scrolling=\"no\" frameborder=\"0\" style=\"display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;\"></iframe>","width":"100%","blog_url":"https://pc.atsuhiro-me.net/"}