Re: Printing dict value for possibly undefined key

2023-11-25 Thread duncan smith via Python-list
On 24/11/2023 16:35, duncan smith wrote: On 24/11/2023 14:31, Loris Bennett wrote: Hi, I want to print some records from a database table where one of the fields contains a JSON string which is read into a dict.  I am doing something like    print(f"{id} {d['foo']} {d['bar']}"

Re: Printing dict value for possibly undefined key

2023-11-25 Thread duncan smith via Python-list
On 24/11/2023 14:31, Loris Bennett wrote: Hi, I want to print some records from a database table where one of the fields contains a JSON string which is read into a dict. I am doing something like print(f"{id} {d['foo']} {d['bar']}") However, the dict does not always have the same keys,

Re: Comparing sequences with range objects

2022-04-10 Thread duncan smith
On 10/04/2022 21:20, Antoon Pardon wrote: Op 9/04/2022 om 02:01 schreef duncan smith: On 08/04/2022 22:08, Antoon Pardon wrote: Well my first thought is that a bitset makes it less obvious to calulate the size of the set or to iterate over its elements. But it is an idea worth exploring

Re: Comparing sequences with range objects

2022-04-09 Thread duncan smith
On 08/04/2022 22:08, Antoon Pardon wrote: Op 8/04/2022 om 16:28 schreef duncan smith: On 08/04/2022 08:21, Antoon Pardon wrote: Yes I know all that. That is why I keep a bucket of possible duplicates per "identifying" field that is examined and use some heuristics at the

Re: Comparing sequences with range objects

2022-04-08 Thread duncan smith
On 08/04/2022 08:21, Antoon Pardon wrote: Op 8/04/2022 om 08:24 schreef Peter J. Holzer: On 2022-04-07 17:16:41 +0200, Antoon Pardon wrote: Op 7/04/2022 om 16:08 schreef Joel Goldstick: On Thu, Apr 7, 2022 at 7:19 AM Antoon Pardon wrote: I am working with a list of data from which I have

Re: mutating a deque whilst iterating over it

2021-02-14 Thread duncan smith
On 13/02/2021 19:12, Dan Stromberg wrote: > On Sat, Feb 13, 2021 at 10:25 AM duncan smith > wrote: > >> On 12/02/2021 03:04, Terry Reedy wrote: >>> On 2/11/2021 3:22 PM, duncan smith wrote: >>> >>>>It seems that I can mutate a deque while i

Re: mutating a deque whilst iterating over it

2021-02-13 Thread duncan smith
On 12/02/2021 03:04, Terry Reedy wrote: > On 2/11/2021 3:22 PM, duncan smith wrote: > >>    It seems that I can mutate a deque while iterating over it if I >> assign to an index, but not if I append to it. Is this the intended >> behaviour? > > Does the deque d

mutating a deque whilst iterating over it

2021-02-11 Thread duncan smith
Hello, It seems that I can mutate a deque while iterating over it if I assign to an index, but not if I append to it. Is this the intended behaviour? It seems a bit inconsistent. Cheers. Duncan >>> from collections import deque >>> d = deque(range(8)) >>> it = iter(d) >>> next(it) 0 >>>

Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread duncan smith
On 27/01/2021 22:41, C W wrote: > Great tutorial Irv, very simple with if-else example, gets the point > across. > > My main takeaway from the discussion so far is that: you can't troubleshoot > Python without some kind of breakpoint or debugger. > [snip] Really? Duncan --

Re: Find word by given characters

2020-11-04 Thread duncan smith
On 04/11/2020 19:12, Avi Gross wrote: > My comments at end: > > -Original Message- > From: Python-list On > Behalf Of duncan smith > Sent: Wednesday, November 4, 2020 1:09 PM > To: python-list@python.org > Subject: Re: Find word by given characters > >

Re: Find word by given characters

2020-11-04 Thread duncan smith
On 04/11/2020 04:21, Avi Gross wrote: > Duncan, my comments below yours at end. > > ---YOURS--- > The Counter approach only requires iterating over the letters once to > construct the letters bag, then each word once to create the relevant word > bag. After that it's (at worst) a couple of

Re: Find word by given characters

2020-11-03 Thread duncan smith
On 03/11/2020 22:14, Avi Gross wrote: > I, too, have wondered what exactly the point was of the required > functionality for SCRABBLE but note you can extend a current word so > additional letters may be available in a game but only if they are an exact > fit to put before, after, or in middle of

Re: Find word by given characters

2020-11-03 Thread duncan smith
On 03/11/2020 23:35, Bischoop wrote: > On 2020-11-03, duncan smith wrote: >>> >> >>>>> from collections import Counter >>>>> letters = 'att' >>>>> letter_counts = Counter(letters) >>>>> word = 'tolerate' >>>&

Re: Find word by given characters

2020-11-03 Thread duncan smith
On 03/11/2020 14:06, Bischoop wrote: > On 2020-11-03, dn wrote: >> >> >> The (full) specs are not clear. There's certainly room for >> misunderstanding. I'd be happier if I could 'see' a full spec or >> recognise a practical application, because then we'd be better able to >> discuss facts.

Re: Find word by given characters

2020-11-02 Thread duncan smith
On 02/11/2020 19:09, dn wrote: > On 02/11/2020 23:29, Bischoop wrote: >> On 2020-11-01, duncan smith wrote: >>>> >>> >>> But this generates the letters counts for each word. They only need to >>> be generated once (outside the for loop). And usi

Re: Find word by given characters

2020-11-01 Thread duncan smith
On 01/11/2020 13:38, Bischoop wrote: > On 2020-11-01, Bischoop wrote: >> I'm working on a script i which user inputs letters and then a printed >> words containing those letters. The scripts works however I can't solve >> one problem , it prints also words in which these letters occur more >>

Re: Confused about np.polyfit()

2020-07-19 Thread duncan smith
On 19/07/2020 16:11, Dino wrote: > On 7/19/2020 4:54 PM, duncan smith wrote: >> >> It depends on what you expect the result to be. There's nothing >> inherently wrong with transforming variables before using least squares >> fitting. Whether it gives you the "best

Re: Confused about np.polyfit()

2020-07-19 Thread duncan smith
On 19/07/2020 11:19, Dino wrote: > > Hi, I am looking at someone else's code trying to understand their use > of numpy.polyfit. > > My understanding was that you can use it to fit polynomials, but > apparently, the original author has used it for logarithmic and > exponential curves as well this

Re: inheriting from long on Python2 or int on Python3

2020-03-21 Thread duncan smith
On 21/03/2020 21:55, Skip Montanaro wrote: >> import sys >> >> class C_hash(int if sys.version_info.major >= 3 else long): > ... > > There's nothing incorrect with your solution. Chris offered another. I > was going to suggest you consider running your code through 2to3 to > see what it does. I

inheriting from long on Python2 or int on Python3

2020-03-21 Thread duncan smith
Hello, I have a class I wrote for Python2 that needs to be made to work on Python3. On Python2 it inherited from long, so it needs to inherit from int on Python3. The following works, but I'm not sure it's the cleanest solution. It's the first time I've wanted / needed to make a parent class

Re: queue versus list

2020-03-20 Thread duncan smith
On 20/03/2020 21:57, Barry wrote: > > >> On 20 Mar 2020, at 00:42, duncan smith wrote: >> >> Bingo. Performance is indistinguishable from that of the list. Thread >> safety is unimportant (for my purposes), but the docs at >> https://docs.python.org/2/librar

Re: queue versus list

2020-03-19 Thread duncan smith
On 19/03/2020 20:40, MRAB wrote: > On 2020-03-19 20:08, duncan smith wrote: >> Hello, >>    I have generator code along the following lines, >> >> >> Q = queue.Queue() >> Q.put(x) >> while not Q.empty(): >> x = Q.get() >>   

queue versus list

2020-03-19 Thread duncan smith
Hello, I have generator code along the following lines, Q = queue.Queue() Q.put(x) while not Q.empty(): x = Q.get() if : yield x else: Q.put() If I change it to, Q = [] Q.append(x) for x in Q: if : yield x else: Q.append() then it runs

Re: What I learned today

2020-02-14 Thread duncan smith
On 14/02/2020 23:21, Dan Stromberg wrote: > On Fri, Feb 14, 2020 at 3:10 PM Stefan Ram wrote: > >> By trial and error (never read documentation!) I found >> that you can count the number of e's in a text by just >> >> Counter( text ).get( 'e' ) >> >> (after »from collections import

Re: distinguishable matplotlib colours / symbols / line styles

2019-12-16 Thread duncan smith
On 16/12/2019 21:08, DL Neil wrote: > On 17/12/19 5:19 am, Chris Angelico wrote: >> On Tue, Dec 17, 2019 at 3:16 AM duncan smith >> wrote: >>> >>> Hello, >>>    Not really specific to Python or matplotlib (but that's what I'm >>> us

distinguishable matplotlib colours / symbols / line styles

2019-12-16 Thread duncan smith
Hello, Not really specific to Python or matplotlib (but that's what I'm using). I'm looking for a good combination of colours and symbols for scatter plots, and combination of colours and line styles for line plots. Too often I find myself producing these when I don't know whether they will

Re: stuck on time

2019-12-08 Thread duncan smith
On 07/12/2019 17:48, RobH wrote: > I am trying to do this project on a pi zero: > > http://frederickvandenbosch.be/?p=1365 > > After overcoming a few errors, I now have the display working and the > start of the code showing on the display, that being the time. > > It doesn't move on to the

Re: Instantiating sub-class from super

2019-10-19 Thread duncan smith
On 18/10/2019 23:57, DL Neil wrote: > On 17/10/19 7:52 AM, MRAB wrote: >> On 2019-10-16 19:43, duncan smith wrote: >>> On 16/10/2019 04:41, DL Neil wrote: >>>> On 16/10/19 1:55 PM, duncan smith wrote: >>>>> On 15/10/2019 21:36, DL Neil wrote: &g

Re: Instantiating sub-class from super

2019-10-16 Thread duncan smith
On 16/10/2019 19:52, MRAB wrote: > On 2019-10-16 19:43, duncan smith wrote: >> On 16/10/2019 04:41, DL Neil wrote: >>> On 16/10/19 1:55 PM, duncan smith wrote: >>>> On 15/10/2019 21:36, DL Neil wrote: >>>>> On 16/10/19 12:38 AM, Rhodri James wrote: &

Re: Instantiating sub-class from super

2019-10-16 Thread duncan smith
On 16/10/2019 04:41, DL Neil wrote: > On 16/10/19 1:55 PM, duncan smith wrote: >> On 15/10/2019 21:36, DL Neil wrote: >>> On 16/10/19 12:38 AM, Rhodri James wrote: >>>> On 14/10/2019 21:55, DL Neil via Python-list wrote: >>> ... >>> So, yes, th

Re: Instantiating sub-class from super

2019-10-15 Thread duncan smith
On 15/10/2019 21:36, DL Neil wrote: > On 16/10/19 12:38 AM, Rhodri James wrote: >> On 14/10/2019 21:55, DL Neil via Python-list wrote: > ... > >>> It seemed better (at the design-level) to have Man( Person ) and >>> Woman( Person ) sub-classes to contain the pertinent attributes, >>> source more

duck typing / library functions

2019-09-12 Thread duncan smith
Hello, The problem I have relates to writing algorithmic code that can handle types with a given API, but where some of the required functionality is implemented as library functions rather than methods. Specifically I have code that uses numpy arrays, but I want to adapt it to use sparse

Re: Import module from a different subdirectory

2019-05-16 Thread duncan smith
On 16/05/2019 22:50, Rich Shepard wrote: > I'm developing a Python3 application using Python3-3.7.3 and > virtualenv-16.5.0 on a Slackware-14.2 host. > > The project directory contains subdirectories, including gui/ (with the > tkinter views) and classes/ with the SQLAlchemy model.py. > > Within

Re: doctest random output?

2019-04-17 Thread duncan smith
On 28/08/2017 20:17, Leam Hall wrote: > On 08/28/2017 11:40 AM, Dennis Lee Bieber wrote: > > ... a bunch of good stuff ... > > I'm (re-)learning python and just trying make sure my function works. > Not at the statistical or cryptographic level.   :) > > Thanks! > > Leam If it's supposed to

Re: in a pickle

2019-03-06 Thread duncan smith
On 07/03/2019 00:18, Ethan Furman wrote: > On 03/06/2019 10:30 AM, duncan smith wrote: > >>  I've been trying to figure out why one of my classes can be >> pickled but not unpickled. (I realise the problem is probably with the >> pickling, but I get the error wh

Re: in a pickle

2019-03-06 Thread duncan smith
On 06/03/2019 20:24, Peter Otten wrote: > duncan smith wrote: > >> On 06/03/2019 16:14, duncan smith wrote: >>> Hello, >>> I've been trying to figure out why one of my classes can be >>> pickled but not unpickled. (I realise the problem is probably wit

Re: in a pickle

2019-03-06 Thread duncan smith
On 06/03/2019 16:14, duncan smith wrote: > Hello, > I've been trying to figure out why one of my classes can be > pickled but not unpickled. (I realise the problem is probably with the > pickling, but I get the error when I attempt to unpickle.) > > A relatively minimal

Re: in a pickle

2019-03-06 Thread duncan smith
[snip] Sorry, this is Python 3.6 on Linux. Duncan -- https://mail.python.org/mailman/listinfo/python-list

in a pickle

2019-03-06 Thread duncan smith
Hello, I've been trying to figure out why one of my classes can be pickled but not unpickled. (I realise the problem is probably with the pickling, but I get the error when I attempt to unpickle.) A relatively minimal example is pasted below. >>> import pickle >>> class test(dict):

Re: sampling from frequency distribution / histogram without replacement

2019-01-18 Thread duncan smith
On 14/01/2019 20:11, duncan smith wrote: > Hello, > Just checking to see if anyone has attacked this problem before > for cases where the population size is unfeasibly large. i.e. The number > of categories is manageable, but the sum of the frequencies, N, > precludes s

Re: sampling from frequency distribution / histogram without replacement

2019-01-15 Thread duncan smith
On 15/01/2019 17:59, Ian Hobson wrote: > Hi, > > If I understand your problem you can do it in two passes through the > population. > The thing is that I start with the population histogram and I want to generate a sample histogram. The population itself is too large to deal with each

Re: sampling from frequency distribution / histogram without replacement

2019-01-15 Thread duncan smith
On 15/01/2019 02:41, Spencer Graves wrote: > > > On 2019-01-14 18:40, duncan smith wrote: >> On 14/01/2019 22:59, Gregory Ewing wrote: >>> duncan smith wrote: >>>> Hello, >>>>    Just checking to see if anyone has attacked this problem

Re: sampling from frequency distribution / histogram without replacement

2019-01-14 Thread duncan smith
On 14/01/2019 22:59, Gregory Ewing wrote: > duncan smith wrote: >> Hello, >>   Just checking to see if anyone has attacked this problem before >> for cases where the population size is unfeasibly large. > > The fastest way I know of is to create a list

sampling from frequency distribution / histogram without replacement

2019-01-14 Thread duncan smith
Hello, Just checking to see if anyone has attacked this problem before for cases where the population size is unfeasibly large. i.e. The number of categories is manageable, but the sum of the frequencies, N, precludes simple solutions such as creating a list, shuffling it and using the first

Re: Injecting methods into instance / class

2018-12-02 Thread duncan smith
On 02/12/2018 18:36, Peter Otten wrote: > duncan smith wrote: > >> Hello, >> I have a lot of functions that take an instance of a particular >> class as the first argument. I want to create corresponding methods in >> the class. I have tried the following, wh

Re: Injecting methods into instance / class

2018-12-02 Thread duncan smith
On 02/12/2018 18:26, Stefan Ram wrote: > duncan smith writes: >> I have tried to find examples of injecting methods into classes without > > Wouldn't the normal approach be to just define a > class with your functions as instance methods? > > main.py > >

Injecting methods into instance / class

2018-12-02 Thread duncan smith
Hello, I have a lot of functions that take an instance of a particular class as the first argument. I want to create corresponding methods in the class. I have tried the following, which (when called from __init__) creates the relevant methods in an instance (Python 3.6). def

Re: Why do integers compare equal to booleans?

2018-11-16 Thread duncan smith
On 16/11/18 14:51, Steve Keller wrote: > Why do the integers 0 and 1 compare equal to the boolean values False > and True and all other integers to neither of them? > > $ python3 > Python 3.5.2 (default, Nov 12 2018, 13:43:14) > [GCC 5.4.0 20160609] on linux > Type "help",

numpy use cases for where and out

2018-09-11 Thread duncan smith
Hello, I'm writing some code for sparse arrays that is intended to pretty much follow the numpy API. Because my arrays can have different default values there is an issue with using the 'out' keyword argument for functions. e.g. If I elementwise multiply 2 arrays with defaults a and b, then

Re: Help Needed : script weird result.

2018-09-01 Thread duncan smith
On 01/09/18 18:11, moha...@gmail.com wrote: > All, > > I m trying to run this small script to find the lowest of the given array of > numbers. The script works fine for various combination of inputs but fails in > a weird way for a particular set of inputs, can anyone point the mistake in >

plotly / dash export data

2018-06-09 Thread duncan smith
Hello, I have been trying to work out how to export data from a dash application. I know little about html or javascript. I can upload data into a table as per the example at https://github.com/plotly/dash-core-components/pull/73. I can edit the data in the table. But I can't find a way of

Re: Instance variables question

2018-04-16 Thread duncan smith
On 16/04/18 17:03, Irv Kalb wrote: > I have been writing OOP code for many years in other languages and for the > past few years in Python. I am writing new curriculum for a course on OOP in > Python. In order to see how others are explaining OOP concepts, I have been > reading as many books

Re: Treatment of NANs in the statistics module

2018-03-17 Thread duncan smith
On 16/03/18 23:16, Steven D'Aprano wrote: > The bug tracker currently has a discussion of a bug in the median(), > median_low() and median_high() functions that they wrongly compute the > medians in the face of NANs in the data: > > https://bugs.python.org/issue33084 > > I would like to ask

Re: plot / graph connecting re ordered lists

2018-01-23 Thread duncan smith
On 23/01/18 23:42, Vincent Davis wrote: > On Tue, Jan 23, 2018 at 4:15 PM Dennis Lee Bieber > wrote: > >> On Tue, 23 Jan 2018 13:51:55 -0700, Vincent Davis >> declaimed the following: >> >>> Looking for suggestions. I have an ordered list of

Re: Speeding up the implementation of Stochastic Gradient Ascent in Python

2018-01-18 Thread duncan smith
On 17/01/18 14:29, leutrim.kal...@gmail.com wrote: > > Hello everyone, > > I am implementing a time-dependent Recommender System which applies BPR > (Bayesian Personalized Ranking), where Stochastic Gradient Ascent is used to > learn the parameters of the model. Such that, one iteration

Re: Problem with assignment. Python error or mine?

2017-12-21 Thread duncan smith
On 21/12/17 19:06, John Ladasky wrote: > On Thursday, December 21, 2017 at 7:37:39 AM UTC-8, MRAB wrote: > >> Python never makes a copy unless you ask it to. >> >> What x1=X does is make the name x1 refer to the same object that X >> refers to. No copying. > > Well, except with very simple,

Re: General Purpose Pipeline library?

2017-11-20 Thread duncan smith
On 20/11/17 15:48, Jason wrote: > a pipeline can be described as a sequence of functions that are applied to an > input with each subsequent function getting the output of the preceding > function: > > out = f6(f5(f4(f3(f2(f1(in)) > > However this isn't very readable and does not support

table class - inheritance, delegation?

2017-03-31 Thread duncan smith
Hello, I need to code up a table class, which will be based on numpy arrays. Essentially it needs to behave like a numpy array, but with a variable associated with each array dimension. It must (at least partially) satisfy the API of an existing class. The main reason for the new class is to

Re: Surprised by the lack of constant folding

2017-03-24 Thread duncan smith
On 24/03/17 19:35, Tim Chase wrote: > Playing around, I came across the following > > $ python3 > Python 3.4.2 (default, Oct 8 2014, 10:45:20) > [GCC 4.9.1] on linux > Type "help", "copyright", "credits" or "license" for more information. from dis import dis def f(x): > ... return

Re: Create ordering of points

2017-02-15 Thread duncan smith
On 15/02/17 13:27, spiess.benja...@googlemail.com wrote: > Hello !:) > I've got a problem which I would really like to solve. > I got a cloud of points (in the simplest example its a 2-dimensional cloud of > points). > First, I want to set one of the points as the initial (or middle) point. >

Re: geopandas bug ?

2017-01-14 Thread duncan smith
On 14/01/17 14:59, Xristos Xristoou wrote: > Τη Σάββατο, 14 Ιανουαρίου 2017 - 4:38:39 μ.μ. UTC+2, ο χρήστης duncan smith > έγραψε: >> On 14/01/17 11:18, Xristos Xristoou wrote: >>> i want to create a simple spatial joing using geopandas but i thing so

Re: geopandas bug ?

2017-01-14 Thread duncan smith
On 14/01/17 11:18, Xristos Xristoou wrote: > i want to create a simple spatial joing using geopandas but i thing so > geopandas has bug ? > > > > geopandas code : > > from geopandas import gpd > import geopandas > points = geopandas.GeoDataFrame.from_file('points.shp') # or geojson etc >

Re: OSError: [Errno 12] Cannot allocate memory

2016-12-01 Thread duncan smith
On 01/12/16 01:12, Chris Kaynor wrote: > On Wed, Nov 30, 2016 at 4:54 PM, duncan smith <duncan@invalid.invalid> wrote: >> >> Thanks. So something like the following might do the job? >> >> def _execute(command): >> p = subprocess.Popen(command, shell=Fa

Re: OSError: [Errno 12] Cannot allocate memory

2016-11-30 Thread duncan smith
On 01/12/16 00:46, Chris Kaynor wrote: > On Wed, Nov 30, 2016 at 4:12 PM, duncan smith <duncan@invalid.invalid> wrote: >> On 30/11/16 17:57, Chris Angelico wrote: >>> On Thu, Dec 1, 2016 at 4:34 AM, duncan smith <duncan@invalid.invalid> wrote: >>>> >>

Re: OSError: [Errno 12] Cannot allocate memory

2016-11-30 Thread duncan smith
On 30/11/16 17:53, Chris Kaynor wrote: > On Wed, Nov 30, 2016 at 9:34 AM, duncan smith <duncan@invalid.invalid> wrote: >> Hello, >> I have had an issue with some code for a while now, and I have not >> been able to solve it. I use the subprocess module to invoke do

Re: OSError: [Errno 12] Cannot allocate memory

2016-11-30 Thread duncan smith
On 30/11/16 17:57, Chris Angelico wrote: > On Thu, Dec 1, 2016 at 4:34 AM, duncan smith <duncan@invalid.invalid> wrote: >> >> def _execute(command): >> # shell=True security hazard? >> p = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, &

Re: OSError: [Errno 12] Cannot allocate memory

2016-11-30 Thread duncan smith
[snip] Sorry, should have said Python 2.7.12 on Ubuntu 16.04. Duncan -- https://mail.python.org/mailman/listinfo/python-list

OSError: [Errno 12] Cannot allocate memory

2016-11-30 Thread duncan smith
Hello, I have had an issue with some code for a while now, and I have not been able to solve it. I use the subprocess module to invoke dot (Graphviz) to generate a file. But if I do this repeatedly I end up with an error. The following traceback is from a larger application, but it appears

Re: need some kind of "coherence index" for a group of strings

2016-11-04 Thread duncan smith
On 03/11/16 16:18, Fillmore wrote: > > Hi there, apologies for the generic question. Here is my problem let's > say that I have a list of lists of strings. > > list1:#strings are sort of similar to one another > > my_nice_string_blabla > my_nice_string_blqbli > my_nice_string_bl0bla >

Re: retain dimensions for numpy slice

2016-10-24 Thread duncan smith
On 24/10/16 19:05, Peter Otten wrote: > duncan smith wrote: > >> Hello, >> I have several arrays that I need to combine elementwise in >> various fashions. They are basically probability tables and there is a >> mapping of axes to variables. I have code

retain dimensions for numpy slice

2016-10-24 Thread duncan smith
Hello, I have several arrays that I need to combine elementwise in various fashions. They are basically probability tables and there is a mapping of axes to variables. I have code for transposing and reshaping that aligns the variables / axes so the usual broadcasting rules achieve the

Re: How to pick out the same titles.

2016-10-16 Thread duncan smith
On 16/10/16 16:16, Seymore4Head wrote: > How to pick out the same titles. > > I have a long text file that has movie titles in it and I would like > to find dupes. > > The thing is that sometimes I have one called "The Killing Fields" and > it also could be listed as "Killing Fields" Sometimes

Re: rdflib subclass problem

2016-03-02 Thread duncan smith
On 02/03/16 08:16, dieter wrote: > duncan smith <duncan@invalid.invalid> writes: > >> I'm just getting to grips with RDF and rdflib, and I've hit >> something I can't figure out. >> >> I have a graph with information on two people. (I haven't shown

rdflib subclass problem

2016-03-01 Thread duncan smith
Hello, I'm just getting to grips with RDF and rdflib, and I've hit something I can't figure out. I have a graph with information on two people. (I haven't shown the imports below because they're scattered around my interactive session and I might reconstruct them incorrectly. Anyone

Re: Catogorising strings into random versus non-random

2015-12-21 Thread duncan smith
On 21/12/15 03:01, Steven D'Aprano wrote: > I have a large number of strings (originally file names) which tend to fall > into two groups. Some are human-meaningful, but not necessarily dictionary > words e.g.: > > > baby lions at play > saturday_morning12 > Fukushima > ImpossibleFork > > >

Re: Catogorising strings into random versus non-random

2015-12-21 Thread duncan smith
On 21/12/15 16:49, Ian Kelly wrote: > On Mon, Dec 21, 2015 at 9:40 AM, duncan smith <duncan@invalid.invalid> wrote: >> Finite state machine / transition matrix. Learn from some English text >> source. Then process your strings by lower casing, replacing underscores >

counting unique numpy subarrays

2015-12-04 Thread duncan smith
Hello, I'm trying to find a computationally efficient way of identifying unique subarrays, counting them and returning an array containing only the unique subarrays and a corresponding 1D array of counts. The following code works, but is a bit slow. ### from collections import

Re: counting unique numpy subarrays

2015-12-04 Thread duncan smith
On 04/12/15 22:36, Albert-Jan Roskam wrote: > Hi > > (Sorry for topposting) > > numpy.ravel is faster than numpy.flatten (no copy) > numpy.empty is faster than numpy.zeros > numpy.fromiter might be useful to avoid the loop (just a hunch) > > Albert-Jan > Thanks, I'd forgotten the difference

Re: counting unique numpy subarrays

2015-12-04 Thread duncan smith
On 04/12/15 23:06, Peter Otten wrote: > duncan smith wrote: > >> Hello, >> I'm trying to find a computationally efficient way of identifying >> unique subarrays, counting them and returning an array containing only >> the unique subarrays and a co

Re: Generating a vector from successive multiplications of another vector from an initial value

2015-10-01 Thread duncan smith
On 01/10/15 21:45, Paulo da Silva wrote: > Hi all. > > What is the fastest way to do the following: > > I have an initial value V and a vector vec of (financial) indexes. > I want to generate a new vector nvec as > > V, V*vec[0], V*vec[0]*vec[1], V*vec[0]*vec[1]*vec[2], ... > > A numpy

Re: How to Calculate NPV?

2015-07-29 Thread duncan smith
On 29/07/15 15:27, ryguy7272 wrote: On Wednesday, July 29, 2015 at 10:21:35 AM UTC-4, ryguy7272 wrote: On Wednesday, July 29, 2015 at 9:59:10 AM UTC-4, ryguy7272 wrote: I am using Spyder Python 2.7. I'm running this sample code. import scipy as sp cashflows=[50,40,20,10,50]

Re: Bug in floating point multiplication

2015-07-02 Thread duncan smith
On 02/07/15 15:52, Steven D'Aprano wrote: Despite the title, this is not one of the usual Why can't Python do maths? bug reports. Can anyone reproduce this behaviour? If so, please reply with the version of Python and your operating system. Printing sys.version will probably do. x = 1 -

Re: Algorithm for Creating Supersets of Smaller Sets Based on Common Elements

2015-02-22 Thread duncan smith
On 21/02/15 19:46, TommyVee wrote: Start off with sets of elements as follows: 1. A,B,E,F 2. G,H,L,P,Q 3. C,D,E,F 4. E,X,Z 5. L,M,R 6. O,M,Y Note that sets 1, 3 and 4 all have the element 'E' in common, therefore they are related and form the following superset: A,B,C,D,E,F,X,Z

Re: Using Python for date calculations

2014-11-21 Thread duncan smith
On 21/11/14 08:35, Steve Hayes wrote: I've finally found a use for Python. When, in the course of my genealogy research, I look at census or burial records, I often want to work out a person's date of birth from their age. It's a simple matter of mental arithmetic, but I sometimes get it

__index__

2014-11-01 Thread duncan smith
Hello, I have a Bloom filter class and want to (partially) serialize instances using hex() or oct(). Instances are mutable, so I can't inherit from long. I thought I'd found the answer when I came across __index__, https://docs.python.org/2/reference/datamodel.html#object.__index__. But it

Re: __index__

2014-11-01 Thread duncan smith
On 01/11/14 16:56, duncan smith wrote: [snip] Sorry, forgot to add that I'm using Python 2.7.6 on Ubuntu 14.04. Cheers. Duncan -- https://mail.python.org/mailman/listinfo/python-list

Re: __index__

2014-11-01 Thread duncan smith
On 01/11/14 18:29, Ethan Furman wrote: On 11/01/2014 10:11 AM, Ned Batchelder wrote: On 11/1/14 12:56 PM, duncan smith wrote: I have a Bloom filter class and want to (partially) serialize instances using hex() or oct(). Instances are mutable, so I can't inherit from long. I thought

Re: [OT] spelling colour / color was Re: Toggle

2014-10-11 Thread duncan smith
On 11/10/14 12:45, mm0fmf wrote: On 11/10/2014 10:37, Christian Gollwitzer wrote: Being a non-native English speaker/writer, I myself stick to the recommendations of the Oxford dictionary. Christian But you do realise the Oxford dictionary is different to English usage and is

Re: [OT] spelling colour / color was Re: Toggle

2014-10-11 Thread duncan smith
On 11/10/14 20:55, William Ray Wing wrote: On Oct 11, 2014, at 3:20 PM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Sat, 11 Oct 2014 16:26:43 +0100, duncan smith buzzard@invalid.invalid declaimed the following: The media have their own quirks when it comes to English. The BBC

Re: [OT] spelling colour / color was Re: Toggle

2014-10-09 Thread duncan smith
On 09/10/14 18:43, mm0fmf wrote: On 09/10/2014 02:29, Steven D'Aprano wrote: Apart from the horrible spelling of colour :-) I've always spelt colour as color when programming and as colour when writing language including documentation about software. colour in a programme doesn't seem

Re: The possibility integration in Python without an equation, just an array-like file

2014-05-16 Thread duncan smith
On 16/05/14 13:57, Enlong Liu wrote: Sorry for this inconvenience. Since my file is a little large, I think it will be more difficult for fellows to check. I will now paste the attachment below. The file for T(E) consists of two columns, the first is E and the second is T(E). What I want is

Re: The possibility integration in Python without an equation, just an array-like file

2014-05-16 Thread duncan smith
On 16/05/14 16:01, Johannes Schneider wrote: If you do not have a closed form for T(E) you cannot calculate the exact value of I(V). Anyway. Assuming T is integrable you can approximate I(V). 1. Way to do: interpolate T(E) by a polynomial P and integrate P. For this you need the equation

Re: random.sample with large weighted sample-sets?

2014-02-16 Thread duncan smith
On 16/02/14 05:08, Ben Finney wrote: Tim Chase python.l...@tim.thechases.com writes: I'm not coming up with the right keywords to find what I'm hunting. I'd like to randomly sample a modestly compact list with weighted distributions, so I might have data = ( (apple, 20), (orange,

Re: random.sample with large weighted sample-sets?

2014-02-16 Thread duncan smith
On 16/02/14 16:35, Charles Allen wrote: How efficient does this thing need to be? You can always just turn it into a two-dimensional sampling problem by thinking of the data as a function f(x=item), generating a random x=xr in [0,x], then generating a random y in [0,max(f(x))]. The xr is

Re: numpy.where() and multiple comparisons

2014-01-17 Thread duncan smith
On 18/01/14 01:51, John Ladasky wrote: Hi folks, I am awaiting my approval to join the numpy-discussion mailing list, at scipy.org. I realize that would be the best place to ask my question. However, numpy is so widely used, I figure that someone here would be able to help. I like to use

Re: Optimizing list processing

2013-12-11 Thread duncan smith
On 11/12/13 23:54, Steven D'Aprano wrote: I have some code which produces a list from an iterable using at least one temporary list, using a Decorate-Sort-Undecorate idiom. The algorithm looks something like this (simplified): table = sorted([(x, i) for i,x in enumerate(iterable)]) table = [i

Re: many constructors in a class?

2013-08-14 Thread duncan smith
On 14/08/13 15:16, climb65 wrote: Hello, here is a small basic question : Is it possible to have more than one constructor (__init__ function) in a class? For instance, to create an object with 2 different ways? If my memory is good, I think that with C++ it is possible. Thanks for your

Re: PEP 450 Adding a statistics module to Python

2013-08-11 Thread duncan smith
On 11/08/13 15:02, Roy Smith wrote: In article mailman.479.1376221844.1251.python-l...@python.org, Skip Montanaro s...@pobox.com wrote: See the Rationale of PEP 450 for more reasons why “install NumPy� is not a feasible solution for many use cases, and why having ‘statistics’ as a

Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread duncan smith
On 24/05/13 10:11, Chris Angelico wrote: On Fri, May 24, 2013 at 6:47 PM, Fábio Santos fabiosantos...@gmail.com wrote: On 24 May 2013 09:41, Chris Angelico ros...@gmail.com wrote: On Fri, May 24, 2013 at 6:14 PM, Peter Brooks peter.h.m.bro...@gmail.com wrote: What is the easiest way to

Re: Ordered dictionaries compared

2013-05-23 Thread duncan smith
On 23/05/13 04:31, Dan Stromberg wrote: What kind of ordered dictionaries? Sorted by key. I've redone the previous comparison, this time with a better red-black tree implementation courtesy of Duncan G. Smith. The comparison is at

  1   2   3   >