« first day (4055 days earlier)      last day (897 days later) » 

1:40 AM
@Aran-Fey thanks @PM2Ring and Aran, the links you guys gave seem to have what I am looking for
 
 
4 hours later…
5:24 AM
Hello Guys
 
 
3 hours later…
8:25 AM
cbg
 
Hi I am encountering an error when dealing with the input shape of CNN stackoverflow.com/questions/70062238/… can you guys help me?
 
@EVision Please take a look at the room rules. We generally ask not to promote questions here in the first 48h.
 
Oh sorry I'm New to here
 
Also, the question already has an answer and it says it's a repost of another question that already has an answer. Perhaps you should work on making the question better answerable before attracting people to it.
Note that changing the scope of the question as answers come in is also a good way to get volunteers to refrain from answering.
 
Thanks for your advice
 
8:50 AM
cbg-ning
 
What are the best portfolio projects to get land on a job as an ML engineer? where can I find such projects if you guys know any resources please reply.
 
 
3 hours later…
11:37 AM
@EVision I am not saying this is the best, but I have an example here which might give some inspiration. However, the one thing it really doesn't cover is large-volume data sources, which would be more akin to what an ML Engineer would have to deal with. You might be able to wrap some Kaggle competition or something
 
 
1 hour later…
12:51 PM
cbg
 
1:40 PM
i am looking to search overlapping patterns(substrings) in a string. but the patterns are from the entire dictionary of words, something similar to implementing linear word puzzle solver. my online lookup led me to Aho–Corasick algorithm. Does anybody have any advice or reference implementation, that would help me.
(eg) "testement" should return ["test","stem","men","testement"...]
i tried using re.finditer(patterns,word) but it consumed the leading patterns. also regex didn't work suitably. Also looping over an entire bag of words seemed unreasonable.
ps. sorry i spelled testament wrongly
 
The Aho–Corasick algorithm uses a trie. How does that relate to your attempt using re?
 
Searching for "aho corasick" on pypi yields at least 2 relevant-looking results, so probably check those out
@MisterMiyagi Well, regex works based on the same principle. But I don't think there's a way to trick regex into doing this particular task
 
What do you consider unreasonable? I frequently iterate over the complete scrabble wordlist when doing language-related projects, and it usually takes about a second.
 
@Aran-Fey Does it? I thought the stdlib regex engine uses backtracking.
 
I could be wrong, but I'd be surprised if there wasn't some kind of state machine involved in regex
 
1:51 PM
>>> import wordlist #a homebrew module of mine that just loads all English words from a json file
>>> words = wordlist.get_words()
>>> [word for word in words if word in "testament"]
['am', 'amen', 'ament', 'en', 'es', 'me', 'men', 'stamen', 'ta', 'tam', 'tame', 'test', 'testa', 'testament']
>>> import timeit
>>> timeit.timeit('[word for word in words if word in "testament"]', globals={'words':words}, number=100)
5.001531971999995
0.05 seconds to find all substrings of "testament", seems reasonable to me
 
@Aran-Fey It 's susceptible to catastrophic backtracking at least: re.search("(a+)+b", "a" * 32)
(Disclaimer: Needed to read up on some regex theory lately. 2/10, can't recommend.)
 
@MisterMiyagi i cant exactly reason out how, but personally i felt a trie based model could reduce the search space. i formerly used 'regex.finditer(adjoinedpatterns, a_string, overlapped=True)` but it turned unsatisfactory. so began my quest
i would timeit too then, i have like around 150 thousand words in my indic dictionary
and without performance bench-marking, i assumed that running this function to decrypt a
paragraph of over 100 words would take time. as it would loop 150 000 * 100 times.
on worst case
 
My word list has 173122 words, so your 150,000 word list should run faster than mine.
Whenever I have a loop with a lot of iterations doing a small amount of work per iteration, I start with a rough initial estimate of one million iterations per second.
In this case it seems that I'm _over_estimating by a factor of 3, because that rate would predict a timeit result of 17, rather than 5.00
 
2:08 PM
@MisterMiyagi I assume that not everything - in particular capture groups - can be (efficiently?) solved with a FSM. But I think there has to be a FSM in there somewhere, because I once tried to write an object-oriented version of regex and it was unbelievably slow. If regex can be reasonably fast without an FSM, I'd love to know how!
 
github.com/python/cpython/blob/main/Modules/_sre.c looks pretty state-machiney to me. Zero ctrl-f results for "backtrack" or "trie", alas
 
I can't read C, but I can see names like state_reset or state_init, so I'd have to agree
 
@Aran-Fey I image you saying this in the same voice people say they can't eat nuts, because they are allergic :D
 
That's fairly accurate :D
 
In any case, none of our theorycrafting about the re module applies to Pingu's problem, because they're using the third party library regex. the stdlib's finditer doesn't have an overlapped parameter.
regex doesn't seem to have any magic ingredient here either, since the benchmark is about as fast as regular lookup
>>> import regex
>>> pattern = regex.compile("|".join(words))
>>> list(pattern.finditer("testament", overlapped=True))
[<regex.Match object; span=(0, 4), match='test'>, <regex.Match object; span=(1, 3), match='es'>, <regex.Match object; span=(2, 8), match='stamen'>, <regex.Match object; span=(3, 5), match='ta'>, <regex.Match object; span=(4, 6), match='am'>, <regex.Match object; span=(5, 7), match='me'>, <regex.Match object; span=(6, 8), match='en'>]
>>> import timeit
>>> timeit.timeit('list(pattern.finditer("testament", overlapped=True))', globals={'pattern': pattern}, number=100)
 
2:18 PM
Huh, it reports test before es? That's interesting
 
And on top of that, regex.compile takes about 30 seconds to execute. Not a big deal if you run it exactly once per program execution, but it raises the question of how badly you want that extra 0.003 seconds per finditer call
 
2:41 PM
Aho-Corasick looks hard to implement, so instead I tried regular old trie lookup. It's about 200 times faster than the other approaches. pastebin.com/raw/7SmcbCyQ
I bet Aho-Corasick really shines when the string you're searching is hundreds of characters long, but if we're looking for english words inside english words, then the average input length is like eight.
 
I think what matters is the quantity of substrings you're looking for. Your trie grows larger the more words you put into it, but a FSM can process an arbitrary number of them in constant time
 
morning cabbages, folks
 
my bare-bones function with your previous list comprehension processed
me 3000 outputs in 30 seconds[wordlist=150 000]. now should i check out your this implementation
if i would need some haste in processing ?
 
2:56 PM
I'll let you be the judge of that :-)
 
@Kevin before that, i think i should invest around 2 days to understand your implementation, some long curve way. should be useful personally.
 
:-)
 
@Kevin Speaking of which, I've started working on a library for solving optimization problems through graph search algorithms. The idea is to make it work with any problem that can be solved by starting at some initial state, and taking steps to (hopefully) get closer to a/the solution. It's not easy to iron out all the details and come up with a working architecture, but there's a good chance I'll manage to work out something reasonably useful.
 
@Aran-Fey I'm fuzzy on the terminology, but I think I agree with you. An FSM is more expensive to construct than a trie, but its lookup time is faster, so it wins when you do a lot of searches.
 
I thought you might be interested in using it for your gaming-related problems and being my unpaid pre-alpha-tester :D
 
3:06 PM
Yeah, I'm becoming more certain that "iterative solution improvement" is a good approach for my gaming-related problems
 
It's rough to write a library for because there are so many different things you might want to do. Do you want to find a solution state or the path to the solution? Or maybe everything is a valid solution, and you're looking for the best one? Or maybe you want to find all the solutions? It's going to be a very messy library no matter what
My hope is that I can hide most of it from the users
 
Finding the best solution state without knowing the path is reasonably useful to me. My #1 practical problem is "which item should I craft and sell in order to maximize my coins/second?". At this stage, I don't need a detailed step-by-step of the actions needed to make the item from scratch, I just need the name of the item.
Most items can be crafted in only 2-3 ways, so if I discover that e.g. Ghost Tears is the most profitable item, then I can just compare the handful of paths to determine the best one. By hand, if need be.
One nice thing about my use case is that the crafting steps don't need to be ordered. "consume 1 gold and 1 silver to produce 1 electrum; consume 1 pickaxe to craft 1 gold; consume 1 pickaxe to craft 1 silver" is just as valid as any other permutation of those steps. I have no problem building up an initial buffer of ingredients before I begin my money making loop.
 
3:30 PM
receiver_email = "abc@gmail.com,cde@gmail.com"
message["To"] = receiver_email
to_addrs =message["To"].split(",")

print(to_addrs)

this getting error
NameError: name 'message' is not defined
how to make message["To"] read
 
message needs to be created before you can assign things to its keys. This is usually done with an assignment statement: message = <something goes here>
There are many factors that go into deciding what to put on the right side of the equals sign. For example, what should the type be?
 
This is in regards with sending mails using python
 
Ok. I recommend that you look through the documentation for whatever mail-sending library you're using. You might find example code that creates a message object, or a class with "Message" in its name, etc.
 
receiver_email = "abc@gmail.com,cde@gmail.com"
message['To'] = receiver_email
message["Subject"] = "test"

smtp_obj.sendmail(from_addr=message["From"],to_addrs=message["To"].split(","), msg=message.as_string())
This is like overview what I am trying to do
but getting error in split part
 
So you're not getting a NameError any more?
 
3:40 PM
getting AttributeError
 
Interesting. Provide an MVCE and I'll investigate further.
 
sure , Thanks
 
anyone know if I can put an image on a webpage such that different parts of the image have different alt text?
 
@inspectorG4dget that's sounds impossible, you might want to split the image into sub images. Or use some js magicary with hover over and x,y position, but it won't technically be the alt text
 
thanks for that sanity check. Good to know I'm maintaining a healthy level of insanity :)
 
3:47 PM
I've never done that before, but this looks relevant: developer.mozilla.org/en-US/docs/Web/HTML/Element/area
I also vaguely remember seeing something like this in the era of Geocities. They might have stitched multiple images together with a zero-border table or something. Not very web 2.0, but if it gets the job done...
 
4:03 PM
<!-- little prototype: -->
<html><body>
<map name="infographic">
    <area shape="rect" coords="0,0,359,408" title="The left lamp." />
    <area shape="rect" coords="499,0,700,408" title="The right lamp." />
</map>
<img usemap="#infographic" src="lamps.png" title="if you can see this, you aren't hovering over a lamp."/>
</body></html>
Requires this image saved as lamps.png, or an image of similar dimensions and lamp amount.
 
oooh! that looks promising. Thanks
 
Interestingly, when you press tab, it outlines each area in turn. Reminds me of the days of Flash games, where you might find clickable easter eggs if you held down tab and looked for highlighted objects.
 
this is exactly what I was looking for. Thank you
 
And the outlines match the shape of the area, instead of just being the area's bounding box. That would have blown my mind in the Geocities era.
 
4:27 PM
interestingly, I'm able to make a local HTML page in which this works, but it doesn't work on my wiki.js wiki page. I might have to use an (ugh!) iframe
 
Quick question: I'm trying to create a unit test where in output, I'm expecting two objects, two lists actually. I was looking for assertEqual to do that but it seems that it cannot be done for checking two outputs. Am I right?
the two outputs would be something like this

`['ab','bc'], [['cc','dd'],['ee','ff']]`
hey @Sankar
 
@AndyK Hey mate
long time no see
 
Keep in mind that a function can only return one object. Even if the return statement looks like return a,b, it's returning a single tuple with elements a and b.
 
I don't understand the question. If you want to verify two outputs, you can either call assertEqual twice or (don't do this) put them in a container, like assertEqual((result1, result2), (expected1, expected2))
 
@Aran-Fey did not know it was possible. That would come handy actually. TY.
(both solutions)
 
4:38 PM
If you do have a return a,b statement, remember to use a tuple literal in your assertEqual call, rather than a list literal
>>> def f():
...     return 1,2
...
>>> import unittest
>>> unittest.TestCase().assertEqual(f(),[1,2])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Programming\Python 3.8\lib\unittest\case.py", line 912, in assertEqual
    assertion_func(first, second, msg=msg)
  File "C:\Programming\Python 3.8\lib\unittest\case.py", line 905, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: (1, 2) != [1, 2]
>>> unittest.TestCase().assertEqual(f(),(1,2))
 
@Kevin if my initial function comes with output results like ['ab','bc'], [['cc','dd'],['ee','ff']], would it be a good pythonic way to create the method that way...?
talking with you suddenly made me think about the way I'm writing my function, test excluded...
@Sankar Sir o>
 
I interpret your question as, "if my function always returns a list/tuple with a static number of elements, should I go out of my way to do return a,b,c, [etc] instead of return my_collection?". I'd say, generally, only do it if it reduces line count without harming readability. Examples forthcoming...
 
@roganjosh Thanks this is helpful.
 
@Kevin yes, ty for the understanding.
 
def quadratic_old(a, b, c):
    l = -b; r = sqrt(4*a*b - a*c); d = 2*a
    result = (l,r,d)
    return result
    #Not concise. No need to create an object just so you can return it.

def quadratic_new(a,b,c):
    l = -b; r = sqrt(4*a*b - a*c); d = 2*a
    return l,r,d
    #this is preferable over quadratic_old. You might even prefer to do it in one line, depending on how much arithmetic you can stomach in a single statement.

def getpixel(x,y):
    return my_image.pixel_rgb_array[y][x]
    #Concise. Consider type annotation if you want the reader to know that this returns an RGB tuple.
 
4:55 PM
@Kevin Ty Kevin. Many thanks for the help.
 
No problem
 
5:16 PM
mean*5,
ZeroDivisionError: division by zero
How is that even possible? mean is either statistics.mean(a_list) or -1 :O ?
 
@Hakaishin you're probably lying
Is it really self.mean with a property? MCVE or bust.
 
so it turns out that the wiki squished the image, so the absolute coordinate system didn't work (and it doesn't allow me to use percentages in the coords system). I had to use some ugly javascript to compute the absolute coords based on the measured percentages and now it works
 
5:30 PM
hmm, weird. After adding the log statement of what mean is, it stops happening. But I still have the old log and stacktrace, where I clearly see it lead to this weird error. I can guarantee you that mean is either statistics.mean(a_list) or -1 I mean I see the code. So that's quite curious, but well it's fixed now
coding machines case
 
@Hakaishin my point is that regular name lookup can't raise a ZeroDivisionError. mean * 5 might, if mean is a crazy class that defines a crazy multiplication that can divide by zero. But even then you'd have to see the internals of that method in the traceback.
I see a comma after mean*5 which makes me think it's just some misunderstood context, or inaccurate line being reported or whatever
 
Yeah that must be it, it's a dict with some stats and a few lines later there could be a division by zero. Funny enough a few runs earlier of the program it reported the right line, somehow it failed now. I wonder why...
 
6:05 PM
recbg
 
6:24 PM
recbg
 
I'm having issues trying to either run a python script in perl using 1 argument, or run python script in python using one argument. Manually you type this in Anaconda2 prompt: python py_swath.py and then hit enter. It will then ask you which file to run and you put something like this: py_swath_ren_xcentre.par then hit enter. I thought I could just do this: import os

os.system("python py_swath.py py_swath_ren_xcentre.par")
 
If the script asks you for input after you start it, that's not a command line argument. You have to write "py_swath_ren_xcentre.par" to its stdin
 
So I can't just os.system it?
 
No. Check out the subprocess module
 
I agree that subprocess is a better choice for doing stuff that a command-prompt usually does. But you may be able to avoid command prompt stuff altogether. many Python programs are designed so that they can be imported from other Python programs. Then you can call whichever function you need. No stdin manipulation required. Hopefully.
 
6:30 PM
@Aran-Fey does IO redirection not work with os?
os.system("python py_swath.py <<<'py_swath_ren_xcentre.par'")
>>> os.system('wc <<<"potato potahtoe"')
sh: 1: Syntax error: redirection unexpected
512
welp
 
Does that write the literal text "py_swath_ren_xcentre.par" to stdin or the contents of that file?
 
@Aran-Fey former. It's the proper way to do echo py_swath_ren_xcentre.par | python py_swath.py
 
except only in bash, apparently? (:
 
No, bash can do that fine. This is OS.
ah, no, sh is not bash
 
The last time I needed to send data to another process' stdin, there was some kind of weird buffering situation where I could only read the label of the input call after I submitted input. So I'd read from stdout and get nothing, I'd write "23" to stdin, and then I'd read from stdout and get "enter your age:".
I believe I complained about this in chat at the time, and someone convinced me that this was perfectly logical and why would I expect anything else?
 
6:33 PM
$ bash -c 'wc <<<"potato potahtoe"'
      1       2      16
$ sh -c 'wc <<<"potato potahtoe"'
sh: 1: Syntax error: redirection unexpected
 
Anyway the lesson is, don't mess with stdin as long as there's an alternative
 
echo py_swath_ren_xcentre.par | python py_swath.py so will this work?
 
I guess it probably would
But you're probably better off getting famiiar with subprocess, that's a more sustainable way forward
 
I'm not a wizard at python... do I need anything before it (import os, etc)
ok
 
@CelesteWilson What you have there is a shell command, so I meant putting that inside os.system()
>>> os.system('echo "potato potahtoe" | wc')
      1       2      16
0
it doesn't spark joy
 
6:39 PM
That opens it, doesn't run it
lol
 
Not sure what "opening" is
$ echo 'this goes to stdin' | python -c 'print("this just in: ", repr(input()))'
this just in:  'this goes to stdin'
this is bash again
 
Every time a shell-based attempt doesn't work, ask yourself, "now am I annoyed enough by this to try an import-based solution instead?". Don't let the sunk cost fallacy tempt you into trying another hundred combinations of pipes and arrows
 
using pipes to direct arrows toward the bullseye is cheating
 
So dumb that it might just work: Create a new file with the namerunswath.bat and contents python py_swath.py py_swath_ren_xcentre.par. Then in your Python script, import os and then os.system("runswath.bat")
Now you have cunningly fooled Python into running a command with one argument, even though it sees zero arguments
On second thought, no, I misunderstood part of the question.
 
it was an excellent solution to a different problem though
 
6:51 PM
Even so, keep batch files in your mind's junk drawer, because they can be useful once every decade or so
The spatula that jams the junk drawer closed from the inside will prevent you from being tempted too easily
Dumb solution #2: open up py_swath.py and replace all instances of input() with sys.argv[1]. Now you can specify the input by passing it as an argument, no stdin needed
 
you mean maintainable solution +1
(just make sure to protect those command line args with single quotes)
 
Well, my excitement about the new error messages was pretty short-lived:
@abc.abstractmethod
NameError: name 'abc' is not defined. Did you mean: 'abs'?
 
that was inevitable
I don't personally think that guesswork is net helpful
 
Type in "no" so it can send your user satisfaction metrics to the Python Corp supercollider
 
7:06 PM
inb4 NameError: name 'no' is not defined. Did you mean: 'None'?
nope, never mind, apparently "no" isn't similar enough to "None"
 
try with a capital N
 
phew, I was worried we'd be trapped in a loop
 
it probably prefers same-length typos
 
Note to self: consider adding singleton value Nope to KevinScript
 
but make it truthy
 
7:10 PM
All literal expressions in KS will have independent denotative and connotative meanings. Nope is false, but you're upbeat about it.
def must_support_internet_explorer(): return Nope
 
>>> import builtins
>>> del builtins.abs
>>> abc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'abc' is not defined
problem solved
 
the stdlib option
 
hey @Kevin, regarding my earlier discussion on overlapping string based puzzle solver. I thought what if and tried a new conceptual implementation. like we split the string(input) first into continuous combinations of valid characters and pack them into a set which we could somehow compare(intersect) with the set of words (dictionary)? my implementation is here for your perusal. pastebin.com/raw/WrvqXzZB
 
By the way, for those of us who suffer the curse of having to write documentation, I discovered this nifty package that inserts interactive links into your code samples. Maybe not the most useful thing ever, but there's literally no reason not to use it
 
@PIngu Sure, that would work. O(N^2) with respect to the length of the input, which is worse than the other approaches... But again I say, if N tops out at 8, then it's probably not going to make much difference.
 
7:21 PM
@Aran-Fey neat
 
@Kevin okay i take that, seemed promising that's why i wanted to verify its sanity
 
> Unable to allocate 5091414050 elements of size 8 bytes.
>>> 5091414050*8/1024**3
37.933990731835365
you don't say
Hmm, that phrasing is confusing, perhaps the factor of 8 is superfluous. That's only 4.7 GB then.
 
It's just saying that each byte is a "size 8", so you know you're working with an 8 bit per byte architecture
 
I kind of assumed that this is always the case...
 
7:37 PM
Yes but I've been campaigning for 9 bits per byte to account for inflation
 
8:13 PM
A "byte" is the smallest unit of memory your PC can address. The word for a byte of 8 bits is "octet"
Thank god for the networking class in university. What would I do without this knowledge?
 
 
2 hours later…
10:04 PM
@AndrasDeak opened it in a text editor instead of running the python script and when in the command window it asks for which file to use, etc
 
10:24 PM
Did you figure out a solution?
 
11:16 PM
Cabbage all!

I found [this](https://aphyr.com/posts/341-hexing-the-technical-interview) today, and thought this might be Kevin's work.
Oh whatever
 

« first day (4055 days earlier)      last day (897 days later) »