Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93395

Re: "normalizing" a value

Path csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.051
X-Spam-Evidence '*H*': 0.90; '*S*': 0.00; 'works.': 0.07; 'modulo': 0.09; 'operator,': 0.09; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'wrote:': 0.16; '(or': 0.21; 'header:In-Reply-To:1': 0.24; '(this': 0.24; 'wondering': 0.25; 'header:User-Agent:1': 0.26; 'this.': 0.28; "i'm": 0.29; 'convert': 0.29; 'values': 0.30; 'to:addr:python-list': 0.35; 'there': 0.36; '(and': 0.36; 'subject:" ': 0.36; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'sure': 0.40; 'where': 0.40; 'called': 0.40; 'places': 0.64; 'music': 0.78; '12:': 0.84; 'do:': 0.91; 'ranging': 0.91; 'subject:value': 0.91
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=JOrGyJ+b c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=EBOSESyhAAAA:8 a=AGkejYDSTmIA:10 a=IkcTkHD0fZMA:10 a=P9NBYvFgXSPQULFFcecA:9 a=QEXdDO2ut3YA:10
X-AUTH mrabarnett@:2500
Date Thu, 02 Jul 2015 01:30:45 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
MIME-Version 1.0
To python-list@python.org
Subject Re: "normalizing" a value
References <fd370a7b-ea6a-48e5-90f4-9d86b89a745e@googlegroups.com>
In-Reply-To <fd370a7b-ea6a-48e5-90f4-9d86b89a745e@googlegroups.com>
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
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>
Newsgroups comp.lang.python
Message-ID <mailman.229.1435797056.3674.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1435797056 news.xs4all.nl 2826 [2001:888:2000:d::a6]:46558
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:93395

Show key headers only | View raw


On 2015-07-02 01:12, bvdp wrote:
> Not sure what this is called (and I'm sure it's not normalize). Perhaps "scaling"?
>
> Anyway, I need to convert various values ranging from around -50 to 50 to an 0 to 12 range (this is part of a MIDI music program). I have a number of places where I do:
>
>     while x < 0: x += 12
>     while x >= 12: x -= 12
>
> Okay, that works. Just wondering if there is an easier (or faster) way to accomplish this.
>
That's called "modular arithmetic". Use the modulo operator, '%':

     x = x % 12

or just:

     x %= 12

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

"normalizing" a value bvdp <bob@mellowood.ca> - 2015-07-01 17:12 -0700
  Re: "normalizing" a value MRAB <python@mrabarnett.plus.com> - 2015-07-02 01:30 +0100
  Re: "normalizing" a value Paul Rubin <no.email@nospam.invalid> - 2015-07-01 17:36 -0700
  Re: "normalizing" a value Denis McMahon <denismfmcmahon@gmail.com> - 2015-07-02 01:06 +0000
  Re: "normalizing" a value random832@fastmail.us - 2015-07-01 21:27 -0400
    Re: "normalizing" a value bvdp <bob@mellowood.ca> - 2015-07-01 18:49 -0700
      Re: "normalizing" a value random832@fastmail.us - 2015-07-01 22:23 -0400
        Re: "normalizing" a value bvdp <bob@mellowood.ca> - 2015-07-01 19:41 -0700
      Re: "normalizing" a value Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-07-01 23:36 -0400
        Re: "normalizing" a value bvdp <bob@mellowood.ca> - 2015-07-02 10:03 -0700
  Re: "normalizing" a value Steven D'Aprano <steve@pearwood.info> - 2015-07-02 12:15 +1000
    Re: "normalizing" a value bvdp <bob@mellowood.ca> - 2015-07-01 19:42 -0700
  Re: "normalizing" a value Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-02 05:41 +0100
  Re: "normalizing" a value Skip Montanaro <skip.montanaro@gmail.com> - 2015-07-02 10:05 -0500

csiph-web