Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Michael Selik Newsgroups: comp.lang.python Subject: Re: fastest way to read a text file in to a numpy array Date: Tue, 28 Jun 2016 14:29:56 +0000 Lines: 30 Message-ID: References: <37b46ad8-8318-4d67-a65c-7dd7a50a3848@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de yAcbcc8l2bS+9RVUVd2TZgVhnEYbR11fkS0mX8ulgC/Q== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:text': 0.04; 'array.': 0.07; 'lines.': 0.07; 'subject:file': 0.07; 'cc:addr :python-list': 0.09; 'closest': 0.09; '2016': 0.16; 'coordinates': 0.16; 'numpy': 0.16; 'received:io': 0.16; 'received:mail- qk0-x22a.google.com': 0.16; 'received:psf.io': 0.16; 'subject:array': 0.16; 'subject:fastest': 0.16; 'wrote:': 0.16; 'email addr:gmail.com>': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'cc:no real name:2**0': 0.22; 'fit': 0.23; 'header:In-Reply-To:1': 0.24; 'wondering': 0.25; 'point.': 0.27; 'points': 0.27; 'define': 0.27; 'message- id:@mail.gmail.com': 0.27; 'fastest': 0.27; 'format,': 0.27; 'function': 0.28; 'bad.': 0.29; 'probably': 0.31; 'option': 0.31; 'problem': 0.33; 'tue,': 0.34; 'file': 0.34; 'received:google.com': 0.35; 'skip:: 10': 0.35; 'something': 0.35; 'possible.': 0.36; 'subject:: ': 0.37; 'skip:x 10': 0.40; "you'll": 0.61; 'distance': 0.63; 'one-time': 0.66; 'repeat': 0.67; 'million': 0.74; 'subject:read': 0.84; 'task,': 0.91; 'broadcasting': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wubwfo/lmXn39dtnwDIKFVNlZN3QYHwcjSZOdLBcLh8=; b=Zgz0rDsZTRXgwUB+hSq7aNIGPPyRH3RUfOiY6fCAe5UxNmbS6TEImQieR7HsxknHEi U2nvGGh3hRNGE0+XTO9+YwNl185HRMW+NLFbixM0MaHuZvDcGtGcwanGTHh2THqivm47 fUxT6NLFCoZDbmEhEVi9CT5RRILsocrzucC62gdy/RWl3TehOUBJqYdTlT4ML+RV/dDg nWHQUkm7fn0ZNowYwTtIF6bYTruZA0Jhd61l0Rj05jw6RxrT+sSIy4RNkpOsbPuF28KJ aeeD1EFVOr5HHf6xZwgvWx+Y3ZpG8nW7WGs5PDUUkLqkTVorIGLcdgmbIYD5jBGheykL Cy7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wubwfo/lmXn39dtnwDIKFVNlZN3QYHwcjSZOdLBcLh8=; b=VWIv7Q/tv8VElAkIZWsyFB89mENI+yWRMcX8IpHvxBjrsaYVkBesoheXchII25zTq+ fUHyLtO12jRdYmiOY7zmhal43a2pj4rsvkm+kCnFCylBYzxZl05jMEv1Al5uKUbbbI3W irQSp0zAfPcz7bl4Jth39cE5a1Sbjt5oyCvy9jrDBHzVQL5YY09i+1FGYqhVUUOJcH36 dnewcBJUVB7pWpiblhDn8l0FOdVkGvJrN6DO1kPulDj4zgyK9789PbBduIgQD14oh/Sc WOu0kNdj/KchA7pNOUZop7J72IZU/jcK21g4glyfMRlXZjbahNu43j1Az/4XCTqNRTxk IGiA== X-Gm-Message-State: ALyK8tJ1wiYM8TwWnC5Tf+4HOY/5LqkaOUkVIU73YGD6a8ndFk8E7hS2AoBPnr9r7Uu5CBR4nZfakkkgYLjvNA== X-Received: by 10.55.50.19 with SMTP id y19mr2426344qky.18.1467124206627; Tue, 28 Jun 2016 07:30:06 -0700 (PDT) In-Reply-To: X-Content-Filtered-By: Mailman/MimeDel 2.1.22 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <37b46ad8-8318-4d67-a65c-7dd7a50a3848@googlegroups.com> Xref: csiph.com comp.lang.python:110702 On Tue, Jun 28, 2016 at 10:08 AM Hedieh Ebrahimi wrote: > File 1 has : > x1,y1,z1 > x2,y2,z2 > .... > > and file2 has : > x1,y1,z1,value1 > x2,y2,z2,value2 > x3,y3,z3,value3 > ... > > I need to read the coordinates from file 1 and then interpolate a value > for these coordinates on file 2 to the closest coordinate possible. The > problem is file 2 is has around 5M lines. So I was wondering what would be > the fastest approach? > Is this a one-time task, or something you'll need to repeat frequently? How many points need to be interpolated? How do you define distance? Euclidean 3d distance? K-nearest? 5 million can probably fit into memory, so it's not so bad. NumPy is a good option for broadcasting the distance function across all 5 million labeled points for each unlabeled point. Given that file format, NumPy can probably read from file directly into an array. http://stackoverflow.com/questions/3518778/how-to-read-csv-into-record-array-in-numpy