Python Forum
Search Results
Post Author Forum Replies Views Posted [asc]
    Thread: Scope of variable confusion
Post: RE: Scope of variable confusion

Using the global keyword is highly discouraged in Python. If you think you must use it, then you are doing something wrong.
ThomasL General Coding Help 10 2,901 Feb-24-2022, 10:53 AM
    Thread: Numpy savetxt, how save number with decimal separator
Post: RE: Numpy savetxt, how save number with decimal se...

Have a look in the docs, as usual: https://numpy.org/doc/stable/reference/g...py.savetxt
ThomasL General Coding Help 1 3,236 May-10-2020, 01:05 PM
    Thread: Understanding how reassignment works
Post: RE: Understanding how reassignment works

Instead of list4[i] = lut[list4[i]]you could do for idx, value in enumerate(lut[list4[i]): list4[i][idx] = valuebut that would be very inefficient. Reassigning is imho the better way to do it.
ThomasL General Coding Help 4 2,259 May-10-2020, 09:31 AM
    Thread: Having a hard time combining two parts of code.
Post: RE: Having a hard time combining two parts of code...

What happens if you try message = f'price: {data["USD"]["last"]}'.encode('ASCII')
ThomasL General Coding Help 6 3,111 May-09-2020, 06:20 PM
    Thread: Understanding how reassignment works
Post: RE: Understanding how reassignment works

The variables labels01112 and labels11112 are pointers to numpy arrays in memory. With list4 = [labels01112, labels11112]you create a list with two pointers pointing to the numpy arrays. With list4[i]...
ThomasL General Coding Help 4 2,259 May-09-2020, 06:07 PM
    Thread: Having a hard time combining two parts of code.
Post: RE: Having a hard time combining two parts of code...

If message needs to be a string then the () brackets are the problem. Hopefully you use a python version >= 3.6 then i would suggest using f-string message = f'price: {data["USD"]["last"]}'
ThomasL General Coding Help 6 3,111 May-09-2020, 04:09 PM
    Thread: How to automatically align an image
Post: RE: How to automatically align an image

The easiest and best way doesn't always match, so I'd replace the "and" with an "or". I don't know either, but I would try a convolutional neural net. (Machine learning / AI)
ThomasL Data Science 1 2,073 May-09-2020, 04:04 PM
    Thread: F-score, Precision, and Recall values
Post: RE: F-score, Precision, and Recall values

Did you use .numpy() twice? return f1.numpy(), precision.numpy(), recall.numpy() f1, precision, recall = computeMetrics([1.0, 2.0, 3.0, 4.0], [1.1, 1.9, 3.2, 4.1]) print('metrics: ', f1.numpy...
ThomasL Data Science 3 2,539 May-09-2020, 08:16 AM
    Thread: struggling w/ fonctions in Python
Post: RE: struggling w/ fonctions in Python

(May-08-2020, 05:56 PM)pyzyx3qwerty Wrote: but the first 2 lines are supposed to make sure the value is lesser than 6 as it is a dice roll. Read the homework of OP: "You must write a function calcul...
ThomasL Homework 7 3,701 May-08-2020, 08:32 PM
    Thread: F-score, Precision, and Recall values
Post: RE: F-score, Precision, and Recall values

You return three values and assign these to one variable, so that´s a tuple. Nothing you really want. Python has an interesting function named dir() to inspect variables Using this one can see that t...
ThomasL Data Science 3 2,539 May-08-2020, 04:10 PM
    Thread: struggling w/ fonctions in Python
Post: RE: struggling w/ fonctions in Python

(May-08-2020, 12:23 PM)Tiril123 Wrote: def calcule_prix(de1, de2): 1 <= de1 <= 6 1 <= de2 <= 6 if de1+de2 =>10: print("Taxe spéciale !","36 pièces") else: print("Taxe régu...
ThomasL Homework 7 3,701 May-08-2020, 03:52 PM
    Thread: Colossus - The Greatest Secret in the History of Computing
Post: Colossus - The Greatest Secret in the History of C...

Hi everyone, are you a computer nerd? have you ever asked yourself what was the first computer? do you want to know about the people who were the seeds to our smartphone civilization? Then watch thi...
ThomasL News and Discussions 0 1,875 May-05-2020, 11:41 AM
    Thread: Multiplex lists using zip
Post: RE: Multiplex lists using zip

If you look at product(values, suits) you get <itertools.product at 0xa2cfb71908>. This is no list, this is an iterator. If you do list(product(values, suits)) than the list() functions takes al...
ThomasL General Coding Help 12 4,648 Dec-02-2019, 06:44 PM
    Thread: Multiplex lists using zip
Post: RE: Multiplex lists using zip

(Dec-02-2019, 05:16 PM)Clunk_Head Wrote: itertools.product(values, suits) must traverse values (len m) and for each must traverse suits (len n) to create the iterable that is returned. Then the iter...
ThomasL General Coding Help 12 4,648 Dec-02-2019, 05:33 PM
    Thread: item = index position - list of list
Post: RE: item = index position - list of list

not exactly. v would be only one integer value. and before as explained in the text. It´s important to read the text carefully always. :-) Here´s my function which can be used for both parts of the d...
ThomasL General Coding Help 9 4,192 Dec-02-2019, 05:24 PM
    Thread: item = index position - list of list
Post: RE: item = index position - list of list

No, there is no list in a list. Just do a print(program). And in this case pointer is an integer variable, which is used as the index into the list. Of course you need to create a loop. In the loop yo...
ThomasL General Coding Help 9 4,192 Dec-02-2019, 04:41 PM
    Thread: Multiplex lists using zip
Post: RE: Multiplex lists using zip

(Dec-02-2019, 04:29 PM)Clunk_Head Wrote: The current solution is O(2*(m*n)), it would be great to get it to O(m*n) like the original list comprehension.Why do you think it is O(2*(m*n)) ? Please ex...
ThomasL General Coding Help 12 4,648 Dec-02-2019, 04:34 PM
    Thread: item = index position - list of list
Post: RE: item = index position - list of list

You read the data from the file, split it into pieces and convert the string digits into integer values in two lines. with open("input.txt") as file: program = [int(num) for line in file for num i...
ThomasL General Coding Help 9 4,192 Dec-02-2019, 04:29 PM
    Thread: generate random variables based on a non-standard t-distribution
Post: RE: generate random variables based on a non-stand...

So None of the 35 distributions you can choose from work for you?
ThomasL General Coding Help 4 3,472 Dec-02-2019, 12:56 PM
    Thread: Advent of Code 2019
Post: RE: Advent of Code 2019

I did puzzle one same way as perfringo. For puzzle 2 i used a recursive approach as i´m still on python 3.7 My solutions for day 1: Hide/Show# part 1 with open("input.txt") as file: masses = [i...
ThomasL News and Discussions 9 5,204 Dec-02-2019, 12:51 PM

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020