Re: question on trax
yes, but I do not see Fn anywhere. Another question is on this line: z = add((x, y)) If I code: z = add(x, y) Then the following exception occurs : *Expected input to be a tuple or list; instead got .* Am Di., 17. Aug. 2021 um 19:21 Uhr schrieb MRAB : > On 2021-08-17 16:50, joseph pareti wrote: > > In the following code, where does tl.Fn come from? i see it nowhere in > the > > documents, i.e I was looking for trax.layers.Fn : > > > > import numpy as np > > *from trax import layers as tl* > > from trax import shapes > > from trax import fastmath > > # > > def Addition(): > > layer_name = "Addition" # don't forget to give your custom layer a > > name to identify > > > > # Custom function for the custom layer > > def func(x, y): > > return x + y > > > > return *tl.Fn*(layer_name, func) > > > [snip] > It comes from using the line: > > from trax import layers as tl > > so it's equivalent to 'trax.layers.Fn'. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Regards, Joseph Pareti - Artificial Intelligence consultant Joseph Pareti's AI Consulting Services https://www.joepareti54-ai.com/ cell +49 1520 1600 209 cell +39 339 797 0644 -- https://mail.python.org/mailman/listinfo/python-list
Re: basic auth request
On 17/08/2021 22:47, Jon Ribbens via Python-list wrote: ... That's only true if you're not using HTTPS - and you should *never* not be using HTTPS, and that goes double if forms are being filled in and double again if passwords are being supplied. I think I agree with most of the replies; I understood from reading the rfc that the charset is utf8 (presumably without ':') and that basic auth is considered insecure. It is being used over https so should avoid the simplest net scanning. I googled a bunch of ways to do this, but many come down to 1) using the requests package or 2) setting up an opener. Both of these seem to be much more complex than is required to add the header. I thought there might be a shortcut or more elegant way to replace the old code, but it seems not thanks -- Robin Becker -- https://mail.python.org/mailman/listinfo/python-list
Re: question on trax
On Tue, 17 Aug 2021 17:50:59 +0200, joseph pareti
declaimed the following:
>In the following code, where does tl.Fn come from? i see it nowhere in the
>documents, i.e I was looking for trax.layers.Fn :
"layers" imports a whole slew of sub modules using
from xxx import *
in order to put all the sub module names at the same level.
https://github.com/google/trax/blob/master/trax/layers/base.py
>From line 748 on...
def Fn(name, f, n_out=1): # pylint: disable=invalid-name
"""Returns a layer with no weights that applies the function `f`.
`f` can take and return any number of arguments, and takes only
positional
arguments -- no default or keyword arguments. It often uses JAX-numpy
(`jnp`).
The following, for example, would create a layer that takes two inputs
and
returns two outputs -- element-wise sums and maxima:
`Fn('SumAndMax', lambda x0, x1: (x0 + x1, jnp.maximum(x0, x1)),
n_out=2)`
The layer's number of inputs (`n_in`) is automatically set to number of
positional arguments in `f`, but you must explicitly set the number of
outputs (`n_out`) whenever it's not the default value 1.
Args:
name: Class-like name for the resulting layer; for use in debugging.
f: Pure function from input tensors to output tensors, where each input
tensor is a separate positional arg, e.g., `f(x0, x1) --> x0 + x1`.
Output tensors must be packaged as specified in the `Layer` class
docstring.
n_out: Number of outputs promised by the layer; default value 1.
Returns:
Layer executing the function `f`.
"""
--
Wulfraed Dennis Lee Bieber AF6VN
[email protected]://wlfraed.microdiversity.freeddns.org/
--
https://mail.python.org/mailman/listinfo/python-list
Re: Regarding inability of Python Module Winsound to produce beep in decimal frequency
On 18/08/21 4:43 pm, Steve wrote:
"The HAL (hardware abstraction layer) function HalMakeBeep()"
Is the beep that opens the pod bay doors?
def HalMakeBeepUsingPCSpeaker():
raise IOError("I'm sorry, I can't do that, Dave.")
--
Greg
--
https://mail.python.org/mailman/listinfo/python-list
RE: Regarding inability of Python Module Winsound to produce beep in decimal frequency
-Original Message- From: Python-list On Behalf Of Greg Ewing Sent: Wednesday, August 18, 2021 11:49 AM To: [email protected] Subject: Re: Regarding inability of Python Module Winsound to produce beep in decimal frequency On 18/08/21 4:43 pm, Steve wrote: >> >> "The HAL (hardware abstraction layer) function HalMakeBeep()" >> Is the beep that opens the pod bay doors? > def HalMakeBeepUsingPCSpeaker(): > raise IOError("I'm sorry, I can't do that, Dave.") I tried that but all it reported was a very slow: "Daisy, Daisy, give me your answer do" And that is when I figured that I knew I should have done that backup -- https://mail.python.org/mailman/listinfo/python-list
Re: Compute working days
Em sábado, 14 de março de 2009 às 13:59:41 UTC-3, Casey escreveu: > How about: > from datetime import date, timedelta > # Define the weekday mnemonics to match the date.weekday function > (MON, TUE, WED, THU, FRI, SAT, SUN) = range(7) > def workdays(start_date, end_date, whichdays=(MON,TUE,WED,THU,FRI)): > ''' > Calculate the number of working days between two dates inclusive > (start_date <= end_date). > The actual working days can be set with the optional whichdays > parameter > (default is MON-FRI) > ''' > delta_days = (end_date - start_date).days + 1 > full_weeks, extra_days = divmod(delta_days, 7) > # num_workdays = how many days/week you work * total # of weeks > num_workdays = (full_weeks + 1) * len(whichdays) > # subtract out any working days that fall in the 'shortened week' > for d in range(1, 8 - extra_days): > if (end_date + timedelta(d)).weekday() in whichdays: > num_workdays -= 1 > return num_workdays Could it include the holidays in Brazil? -- https://mail.python.org/mailman/listinfo/python-list
Re: Compute working days
On 2021-08-18 20:57, Bruno Lirio wrote: Em sábado, 14 de março de 2009 às 13:59:41 UTC-3, Casey escreveu: How about: from datetime import date, timedelta # Define the weekday mnemonics to match the date.weekday function (MON, TUE, WED, THU, FRI, SAT, SUN) = range(7) def workdays(start_date, end_date, whichdays=(MON,TUE,WED,THU,FRI)): ''' Calculate the number of working days between two dates inclusive (start_date <= end_date). The actual working days can be set with the optional whichdays parameter (default is MON-FRI) ''' delta_days = (end_date - start_date).days + 1 full_weeks, extra_days = divmod(delta_days, 7) # num_workdays = how many days/week you work * total # of weeks num_workdays = (full_weeks + 1) * len(whichdays) # subtract out any working days that fall in the 'shortened week' for d in range(1, 8 - extra_days): if (end_date + timedelta(d)).weekday() in whichdays: num_workdays -= 1 return num_workdays Could it include the holidays in Brazil? Yes. The algorithms calculates the number of working days, assuming no holidays, so you'd then subtract any working days between the start and end dates that are actually holidays. -- https://mail.python.org/mailman/listinfo/python-list
Re: basic auth request
On 2021-08-18, Robin Becker wrote: > On 17/08/2021 22:47, Jon Ribbens via Python-list wrote: > ... >> That's only true if you're not using HTTPS - and you should *never* >> not be using HTTPS, and that goes double if forms are being filled >> in and double again if passwords are being supplied. > > I think I agree with most of the replies; I understood from reading > the rfc that the charset is utf8 (presumably without ':') The username can't contain a ':'. It shouldn't matter in the password. > and that basic auth is considered insecure. It is being used over > https so should avoid the simplest net scanning. It's not insecure over HTTPS. Bear in mind the Basic Auth RFC was written when HTTP was the standard and HTTPS was unusual. The positions are now effectively reversed. > I googled a bunch of ways to do this, but many come down to 1) using > the requests package or 2) setting up an opener. Both of these seem to > be much more complex than is required to add the header. > > I thought there might be a shortcut or more elegant way to replace the > old code, but it seems not It's only a trivial str/bytes difference, it shouldn't be any big deal. But using 'requests' instead is likely to simplify things and doesn't tend to be an onerous dependency. -- https://mail.python.org/mailman/listinfo/python-list
Re: question on trax
On 19/08/21 3:59 am, joseph pareti wrote: Another question is on this line: z = add((x, y)) If I code: z = add(x, y) Then the following exception occurs : *Expected input to be a tuple or list; instead got .* What exactly is your question? Does add((x, y)) not do what you want? If not, you'll have to tell us what you do want. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Upcoming book: Learn Python through Nursery Rhymes and Fairy Tales
Hi everyone, I'm writing a new Python book for beginners called Learn Python through Nursery Rhymes and Fairy Tales. It teaches Python concepts by translating the classic tales into Python programs. I launched the book on Kickstarter for pre-order- you can check it out here: https://www.kickstarter.com/projects/914595512/learn-python-through-nursery-rhymes-and-fairy-tales I'd be happy to hear any questions or comments you have. Thank you, Shari -- https://mail.python.org/mailman/listinfo/python-list
