Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101363
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Peter Otten <__peter__@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: SUM only of positive numbers from array |
| Date | Fri, 08 Jan 2016 09:17:42 +0100 |
| Organization | None |
| Lines | 27 |
| Message-ID | <mailman.59.1452241084.2305.python-list@python.org> (permalink) |
| References | <50beb098-f854-4b17-b157-1be075d91f4d@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Trace | news.uni-berlin.de F8haxBumQP1ugb/h1W96UwD227ZMbfJ5qvptj7+iW+YQ== |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'true,': 0.04; 'false,': 0.07; 'problem?': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'count,': 0.16; 'help...': 0.16; 'numpy': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:array': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'all,': 0.20; 'import': 0.24; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'subject:numbers': 0.29; 'code': 0.30; 'should': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'subject:from': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'skip:n 10': 0.62; 'sum': 0.69; 'sum.': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57bd972e.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:101363 |
Show key headers only | View raw
Davorin Bajic wrote: > Hi All, > > I should help... > > I want to calculate the sum of a positive number, for each row: > > > x = ((mat_1 / s_1T)-(s_2 / total)) > y = (np.sum(x > 0, axis=1)).reshape(-1, 1).tolist() > > However, this part of the code only calculation count, I need sum. > > Any ideas how to solve this problem? Use x>0 as "index": >>> import numpy >>> x = numpy.array([1, -2, 3]) >>> x>0 array([ True, False, True], dtype=bool) >>> x[x>0] array([1, 3]) >>> x[x>0].sum() 4
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
SUM only of positive numbers from array Davorin Bajic <davorinbajic@gmail.com> - 2016-01-07 20:12 -0800 Re: SUM only of positive numbers from array Peter Otten <__peter__@web.de> - 2016-01-08 09:17 +0100 Re: SUM only of positive numbers from array Davorin Bajic <davorinbajic@gmail.com> - 2016-01-08 04:33 -0800
csiph-web