Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeder1.xsusenet.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'elements.': 0.07; 'energy,': 0.09; 'integers': 0.09; 'spec': 0.09; 'works.': 0.09; 'cc:addr:python-list': 0.11; '2.7': 0.14; '105,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'numpy': 0.16; 'only?': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'bit': 0.19; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'skip:l 30': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'message-id:@mail.gmail.com': 0.30; '25,': 0.31; 'but': 0.35; 'received:google.com': 0.35; 'installing': 0.36; 'processed': 0.36; 'list': 0.37; 'same.': 0.38; 'pm,': 0.38; 'does': 0.39; 'read': 0.60; 'become': 0.64; 'effectively': 0.66; 'latest': 0.67; 'mar': 0.68; '2015': 0.84; 'issues:': 0.84; "paul's": 0.84; 'subject:looking': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=Hm8ASAAQTFM+XT9ZRVbWC6ZGZv52T0zW/FcqChBN02w=; b=qSylTLXECBKyPTPaItYOlwOZeDLXtIuLTx3PgPhFsajF6XZMmVO+lqCSDLxNxRqMIP g84OaBGlDJaf8CiyPjCh+9niaRFQfMVmV/NN7+KK8E5zlfi4oHkyBwVCXVW5vPHv4zbA H7Hedory236n3xk0Ln7xLnSZV4eESFByWGVMtMblrLwKqn43am9lIoiY/KMRqBnuvKQX Vqp4cJUrKfqydm62s3K7yUWVGKxD9/vpIBGLjux1Ei8Cjy/zOGQhvV1Q9Yk4Lg0zf+mo ScG5Y7qY6QXxIqe6MMpA6WP/PbdYImtnsPogF0145yVMhfk5SnaUqGpJI/9ad+swYIIN vvSA== MIME-Version: 1.0 X-Received: by 10.50.79.161 with SMTP id k1mr27199008igx.14.1427259905813; Tue, 24 Mar 2015 22:05:05 -0700 (PDT) In-Reply-To: <0e0fbfec-0265-490b-9300-d2c1f2bb4391@googlegroups.com> References: <874mp97mf9.fsf@jester.gateway.sonic.net> <0e0fbfec-0265-490b-9300-d2c1f2bb4391@googlegroups.com> Date: Wed, 25 Mar 2015 16:05:05 +1100 Subject: Re: Newbie looking for elegant solution From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1427259914 news.xs4all.nl 2834 [2001:888:2000:d::a6]:60066 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87931 On Wed, Mar 25, 2015 at 3:46 PM, wrote: > Now I have just read the latest spec and speed/memory may become issues: > > 1 bit images of a size of 1024 x 1280 need to be processed this way, so > 1310720 list elements. Also needs to be 2.7 only. > > Any recommendations? 2.7 only? Then my solution won't work (I just tried to port it, and integers don't have to_bytes). Paul's solution works. Here's an alternative: >>> import numpy >>> list(numpy.packbits(numpy.array(l),-1)) [177, 105, 117] Of course, this does mean installing numpy. It is crushing the nut with the triphammer - an absurd extravagance of energy, but the nut is effectively crushed all the same. ChrisA