Deutsch   English   Français   Italiano  
<mailman.38.1720846018.2981.python-list@python.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!fu-berlin.de!uni-berlin.de!not-for-mail
From: <avi.e.gross@gmail.com>
Newsgroups: comp.lang.python
Subject: RE: Relatively prime integers in NumPy
Date: Sat, 13 Jul 2024 00:46:55 -0400
Lines: 598
Message-ID: <mailman.38.1720846018.2981.python-list@python.org>
References: <SA0PR09MB6363F3E6B493202E73869DF4DBDA2@SA0PR09MB6363.namprd09.prod.outlook.com>
 <00e801dad3bf$473daed0$d5b90c70$@gmail.com>
 <DM8PR09MB63603191F5509E5013D1BEDCDBA52@DM8PR09MB6360.namprd09.prod.outlook.com>
 <DM8PR09MB636055F61171899BF14B01D3DBA62@DM8PR09MB6360.namprd09.prod.outlook.com>
 <011801dad4b7$44a07100$cde15300$@gmail.com>
 <DM8PR09MB6360AD8A1C512FAC31F32F70DBA72@DM8PR09MB6360.namprd09.prod.outlook.com>
 <01ef01dad4df$aff92ff0$0feb8fd0$@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain;
	charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de ZxnPvHKRfftD/4I2Vtz5sgNq0D9bSW76a64AxnSfMkcw==
Cancel-Lock: sha1:rvhelq++Kq/GiLLePpaK8YhQuJc= sha256:3TFJef1SxKGkmFg20c2Ub/13RD1v6l+zB6FROvMFxvY=
Return-Path: <avi.e.gross@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
 reason="2048-bit key; unprotected key"
 header.d=gmail.com header.i=@gmail.com header.b=On2P0kLj;
 dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'looks': 0.02; 'fairly':
 0.05; '>>>': 0.07; 'explanation': 0.07; 'loops.': 0.07;
 'matches': 0.07; 'modules': 0.07; 'enough.': 0.09; 'indeed.':
 0.09; 'mechanism': 0.09; 'much,': 0.09; 'numpy': 0.09; 'routine':
 0.09; 'search,': 0.09; 'skip:z 20': 0.09; 'url-
 ip:13.107.246.67/32': 0.09; 'url-ip:13.107.246/24': 0.09; '>':
 0.14; 'import': 0.15; 'url:mailman': 0.15; '(1,': 0.16; '1),':
 0.16; '2024': 0.16; '3:10': 0.16; 'benchmarking': 0.16;
 'divisors': 0.16; 'examples.': 0.16; 'far,': 0.16; 'interpreted.':
 0.16; 'itertools': 0.16; 'loops': 0.16; 'modules,': 0.16;
 'numpy,': 0.16; 'numpy.': 0.16; 'numpy?': 0.16; 'patterns.': 0.16;
 'prime': 0.16; 'procedure': 0.16; 'prompts': 0.16; 'received:mail-
 qv1-xf2e.google.com': 0.16; 'relatively': 0.16; 'skip:0 210':
 0.16; 'somewhat': 0.16; 'sorry.': 0.16; 'step.': 0.16; 'tuples':
 0.16; 'url-ip:3.215/16': 0.16; 'url:urldefense': 0.16; 'url:v3':
 0.16; 'using.': 0.16; 'python': 0.16; 'code.': 0.17; 'message-
 id:@gmail.com': 0.18; 'solve': 0.19; 'implement': 0.19; 'to:addr
 :python-list': 0.20; 'issue': 0.21; 'written': 0.22; 'languages':
 0.22; 'i.e.': 0.22; 'maybe': 0.22; 'version': 0.23; 'code': 0.23;
 '(and': 0.25; 'skip:- 10': 0.25; 'depends': 0.25; 'url:listinfo':
 0.25; 'cannot': 0.25; 'programming': 0.25; '11,': 0.26; 'friday,':
 0.26; 'else': 0.27; 'bit': 0.27; 'function': 0.27; 'done': 0.28;
 '>>>': 0.28; 'expect': 0.28; 'mostly': 0.28; 'purpose': 0.28;
 'email addr:python.org>': 0.28; 'example,': 0.28; 'suggest':
 0.28; 'module': 0.31; 'think': 0.32; 'question': 0.32; '(as':
 0.32; 'carefully': 0.32; 'collected': 0.32; 'needed,': 0.32;
 'python-list': 0.32; 'structure': 0.32; 'develop': 0.32; 'but':
 0.32; "i'm": 0.33; 'there': 0.33; 'particular': 0.33; 'numbers':
 0.67; 'skip:n 30': 0.67; 'back': 0.67; 'outside': 0.67; 'url-
 ip:104.18/16': 0.67; 'url-ip:18/8': 0.67; 'url-ip:3/8': 0.67;
 '8bit%:69': 0.69; '8bit%:91': 0.69; '8bit%:96': 0.69; '8bit%:99':
 0.69; 'candidate': 0.69; 'compare': 0.69; 'enclosed': 0.69;
 'factor': 0.69; 'functional': 0.69; 'latter': 0.69; 'skip:\xe2
 20': 0.69; 'url:us': 0.69; 'within': 0.69; '8bit%:43': 0.70;
 'interesting': 0.71; 'speed': 0.71; 'skip:\xe2 10': 0.71;
 '8bit%:89': 0.75; '8bit%:92': 0.75; '8bit%:94': 0.75; '8bit%:78':
 0.76; 'combination': 0.76; 'factors': 0.76; 'languages,': 0.76;
 'sent:': 0.78; 'highly': 0.78; '0in': 0.81; '8bit%:95': 0.84;
 'reasons': 0.84; '8bit%:76': 0.84; '8bit%:97': 0.84; 'atd': 0.84;
 'axis': 0.84; 'combinations': 0.84; 'email name:<python-list':
 0.84; 'indices': 0.84; 'lot.': 0.84; 'popov': 0.84; 'skip:& 50':
 0.84; 'skip:1 70': 0.84; 'url:--': 0.84; '8bit%:98': 0.91;
 'expensive': 0.91; 'skip:\xd0 10': 0.91; 'aspects': 0.93;
 'interest.': 0.93; 'hidden': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1720846015; x=1721450815; darn=python.org;
 h=thread-index:content-language:mime-version:message-id:date:subject
 :in-reply-to:references:to:from:from:to:cc:subject:date:message-id
 :reply-to; bh=fAEm6aatoSX1rIXfZ2f867FjgAv63Il5EGAx9SzelSE=;
 b=On2P0kLjtTMe5exTZmU+2rsR0cHxw3urmolJmsW4yY7TFqGvJOfYOjDOdd9yL4YV/A
 3Sa4l9ObHzzV4a08OhgUCfyZjvqxArT4aE71Tm4FoIT2TBVzO2b8FSeI9wSyR14HbhI5
 PeFZnXz1r6Nnhi3pErBCjGvDYGWHaGdseXld/Mk0iLG2qNzr9CJdzjJftqktkTIi9agA
 K2D4vMYQKUSBCypk8Y43UT+l0g2pY7V1vYQwLp/DFM0b4fEGeNOYDXeE8MGXghBPE0WS
 lL4p2mQGACroeNUhQYoo1VKIulqDEifDlirZ2kXFhBpzVe5AShMSPCAFDwYROHkXv4S3
 wbug==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1720846015; x=1721450815;
 h=thread-index:content-language:mime-version:message-id:date:subject
 :in-reply-to:references:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=fAEm6aatoSX1rIXfZ2f867FjgAv63Il5EGAx9SzelSE=;
 b=P9SxkFyoSKMSGiEfAGVdaSgaojq2AmjDcHDOSojivHp2Ug2UnUbM+Hhsgh5TD9jPYC
 tH9gw3xZrh8CXhjfh3MHF8os1X7fwE9BtZEnbUSjJgAba6yr4O4rhkbdZzEjFn1tJU2U
 ENPXfKg29Bs5mNy1HDZyh6YOTP7i3eG6xbDy47P/2NxVXGllSjQ2zdEsFsFzUs9ucgJ+
 Ub9m2tIFcuDAwKgwQaox01FJjHKfQKdCGbNNvbqNCsscpFMF+WfFB0HuOZBoWCdEOeTP
 8yUZwbv3G9g7PcbsQ/fh0ZKdX5BipP97jWSNU2j8p2AcIpCbcNyttyjrkE3jMFFgGLW4
 I/7w==
X-Forwarded-Encrypted: i=1;
 AJvYcCVTaK3chMxPAAeCcoKGJll0sWCLyKjtWCgT3iwDABYJNRA900CO/SHGf5LapT4liSJr23Moe+xQ8vSPVrCpBTm4V0fZNU62
X-Gm-Message-State: AOJu0YxtaEG3wZBK1anYPSkFlVeb1pCmPYFHRMk6hPaNTDunUn6X/KbM
 ndnr2m1UATDOkZeBtrqhnpfwkiTiyIjedWafbtibAHxT2d1yGbKc
X-Google-Smtp-Source: AGHT+IEkqVESFTLUVLCTppMNlzDnHf14hptJUcenecrUIbyaSQ5rOM7X4Cm8/QRRHv11W7OodX2iHg==
X-Received: by 2002:a05:6214:2581:b0:6b1:e371:99d9 with SMTP id
 6a1803df08f44-6b61bc7e7ddmr197253846d6.8.1720846014657; 
 Fri, 12 Jul 2024 21:46:54 -0700 (PDT)
In-Reply-To: <DM8PR09MB6360AD8A1C512FAC31F32F70DBA72@DM8PR09MB6360.namprd09.prod.outlook.com>
X-Mailer: Microsoft Outlook 16.0
Content-Language: en-us
Thread-Index: AQHaqdYQj6Isi+wDzs9EemRqPkPTEQJmM6ydAUtEEooBr5vKQQKMAsT/Aml9nvCxoa0LoA==
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <01ef01dad4df$aff92ff0$0feb8fd0$@gmail.com>
X-Mailman-Original-References: <SA0PR09MB6363F3E6B493202E73869DF4DBDA2@SA0PR09MB6363.namprd09.prod.outlook.com>
 <00e801dad3bf$473daed0$d5b90c70$@gmail.com>
 <DM8PR09MB63603191F5509E5013D1BEDCDBA52@DM8PR09MB6360.namprd09.prod.outlook.com>
 <DM8PR09MB636055F61171899BF14B01D3DBA62@DM8PR09MB6360.namprd09.prod.outlook.com>
 <011801dad4b7$44a07100$cde15300$@gmail.com>
 <DM8PR09MB6360AD8A1C512FAC31F32F70DBA72@DM8PR09MB6360.namprd09.prod.outlook.com>
Bytes: 27655

Dmitry,

=20

Efficiency of several kinds is hotly debated and sometimes it depends a =
lot on what is done within loops.

=20

Many suggest a mild speed up of some comprehensions over loops but the =
loops are not gone but somewhat hidden and perhaps some aspects are =
faster for having been written in C carefully and not interpreted.

=20

Comprehensions (and there are other versions that generate dictionaries =
and tuples and sets) may also be sped up a bit for other reasons like =
your fairly expensive APPPEND that has to keep finding the end o f a =
growing list and is not done the same way in a comprehension.

=20

If you do a search, you find many opinions including on using functional =
programming techniques such as map/reduce. There are also=20

=20

Your particular case is interesting because it just makes all =
combination of three variables. Some languages, like R, have functions =
that do this for you, like expand.grd. Python has many modules, like =
itertools that do things including combinations but perhaps not designed =
for your case.=20

=20

Here is a version of your scenario:

=20

import itertools

a =3D range(3)

b =3D range(4)

c =3D range(5)

=20

list(itertools.product(a,b,c))

=20

The result comes as tuples but as you are moving the result into numpy, =
does it matter:

=20

>>> list(itertools.product(a,b,c))

[(0, 0, 0), (0, 0, 1), (0, 0, 2), (0, 0, 3), (0, 0, 4), (0, 1, 0), (0, =
1, 1), (0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 0), (0, 2, 1), (0, 2, 2), =
(0, 2, 3), (0, 2, 4), (0, 3, 0), (0, 3, 1), (0, 3, 2), (0, 3, 3), (0, 3, =
4), (1, 0, 0), (1, 0, 1), (1, 0, 2), (1, 0, 3), (1, 0, 4), (1, 1, 0), =
(1, 1, 1), (1, 1, 2), (1, 1, 3), (1, 1, 4), (1, 2, 0), (1, 2, 1), (1, 2, =
2), (1, 2, 3), (1, 2, 4), (1, 3, 0), (1, 3, 1), (1, 3, 2), (1, 3, 3), =
(1, 3, 4), (2, 0, 0), (2, 0, 1), (2, 0, 2), (2, 0, 3), (2, 0, 4), (2, 1, =
0), (2, 1, 1), (2, 1, 2), (2, 1, 3), (2, 1, 4), (2, 2, 0), (2, 2, 1), =
(2, 2, 2), (2, 2, 3), (2, 2, 4), (2, 3, 0), (2, 3, 1), (2, 3, 2), (2, 3, =
3), (2, 3, 4)]

========== REMAINDER OF ARTICLE TRUNCATED ==========