« first day (3507 days earlier)      last day (1442 days later) » 

8:45 AM
I have a small question. Will it be horrible to store DateTime information in the db in Django with the local time zone of a given user instead of UTC? In other words, using django.utils.timezone.localtime() instead of django.utils.timezone.now()?
 
@ArafatKhan is it a problem if the user goes through daylight saving?
It usually is
 
@AndrasDeak Will localtime() not respect any DST?
 
9:18 AM
1. I don't know. 2. My point is that if it does respect it you will get gaps or worse: overlaps with non-monotonic times.
User logs in at 2:50, logs out at 2:10
But that might also be an issue with server-side DST, I have no idea about this in practice. Just something that occurred to me as a potential pitfall.
I mean utils.timezone.now() doesn't sound too UTC to me
 
9:33 AM
So do you think this could be a better and cleaner way: storing all the DataTime info in UTC, then use .astimezone() to convert to a specific time zone set up by the end-user?
@AndrasDeak And by the way it acutally is UTC aware time. According to the docs utils.timezone.now() will always use UTC attached DateTimes.
 
I don't know the specific methods for the Django ORM but you should be saving time in UTC
 
@ArafatKhan OK
 
So I believe using UTC to store datetime would be better? And then convert them as needed?
 
Just found out that set operations do not respect ordering of operands. Can someone confirm this?
class HashKV:
    def __init__(self, k, v): self.k, self.v = k, v
    def __hash__(self): return hash(self.k)
    def __eq__(self, other): return self.k == other.k
    def __repr__(self): return f'{self.k}: {self.v}'

search = {HashKV(1, '?')}
def identical_in(a, b): return next(iter(a)) is next(iter(b))
print(identical_in(search, search & {HashKV(1, 1)}))
print(identical_in(search, {HashKV(1, 1)} & search))
print(identical_in(search, search & {HashKV(1, 1), HashKV(2, 2)}))
print(identical_in(search, {HashKV(1, 1), HashKV(2, 2)} & search))
Should print True, False, True, False (or the inverse) if my assumption is false.
 
9:49 AM
next(iter(a)) is next(iter(b)) on purpose?
And if your assumption is false shouldn't reversing the order not matter?
I get False, True, True, True
In [2]: search
Out[2]: {1: ?}

In [3]: search & {HashKV(1, 1)}
Out[3]: {1: 1}

In [4]: {HashKV(1, 1)} & search
Out[4]: {1: ?}

In [5]: search & {HashKV(1, 1), HashKV(2, 2)}
Out[5]: {1: ?}

In [6]: {HashKV(1, 1), HashKV(2, 2)} & search
Out[6]: {1: ?}
Ah, you're hashing and comparing based on key, so the value is dangling and it's all undefined
 
@AndrasDeak Need to check which item I get, but can't use == since __eq__ is borked. And the setup was way too complicated for me to think about just checking the value...
 
I don't think you can make assumptions about which "identical" element gets chosen from multiple
In [10]: {HashKV(1, 1), HashKV(1, '?')}
Out[10]: {1: 1}

In [11]: {HashKV(1, '?'), HashKV(1, 1)}
Out[11]: {1: ?}
Is that not the same thing?
 
Apparently. It was based on a Q by some "This is super easy in C++, herp" OP, but I would have assumed Python consistently picks elements from either the first or second set.
 
the only part that I find a bit surprising is the difference between search & {HashKV(1, 1)} and search & {HashKV(1, 1), HashKV(2, 2)}
 
Yes, that's the one I don't get.
 
9:57 AM
but I also don't know how sets really work so...
 
Im trying to make a image matrix from a random image in my folder but i get this error:
        FileNotFoundError: [Errno 2] No such file or directory: '3.pgm'
my code:
    RImageMatrix = np.array(Image.open(random.choice(os.listdir(r"C:\Users\DELL\PycharmProjects\RajaClassTest\venv\Include\Test"))))
    print(RImageMatrix)
 
@KhwajaHussamQuasmi error seems clear enough
you have to add the full path back, I bet
 
@AndrasDeak but this is the full path. i've used this to select images but it gives an error at random
 
"3.pgm" is not the full path.
maybe stop for a moment and look at what you're really passing to Image.open?
no need to put everything on one line
 
got it bro. i was trying to see if i could work it out in one line of code
thanks man
 
10:01 AM
@AndrasDeak me neither, but I did not expect to be that wrong.
 
@AndrasDeak out curiosity if i want to do this in one line of code how should i like approach this?
 
@KhwajaHussamQuasmi doing it right without debugging
@MisterMiyagi Martijn or user2357112 probably knows
 
10:17 AM
@MisterMiyagi I had a Eureka moment. How would you implement intersection? Loop the shorter set first, right? So, null hypothesis: if they are unequal length, order doesn't matter. For equal length, choose either left or right in the implementation.
no time to test it though, but adding the (2,2) to the ? side might help check it
 
user11702787
what is a function invocation ? stumbled on this term
 
@We..are..one sounds like a function call
 
user11702787
@AndrasDeak that should be it
 
10:32 AM
@AndrasDeak good point, sounds reasonable.
 
10:56 AM
what is the equivalent of liste = [x+1 for x in liste] in a "normal" for loop ?
 
@roblox have you tried figuring it out yourself?
Do you know how list comprehensions work?
 
kind of im search for the correct expression
 
This seems like a good example to learn
@roblox "list comprehension site:docs.python.org"
 
@AndrasDeak After careful testing, we conclude the Andras Hypothesis to be true with at least p < 0.05.
 
11:23 AM
\o/
lol, someone turned an upvote on my answer into a downvote plus a random downvote
must have stepped on that toe real bad
Perhaps they wanted to downvote me in the first place, but they also couldn't do that right.
 
11:45 AM
Being downvoted sloppily can sting much more than being downvoted properly...
 
I just find it amusing
 
12:06 PM
@wim speaking of amusing, your meta answers are undeleted and again with 1-2 delvotes each. Hilarious.
 
12:17 PM
after enough of those you just look at it, might blurt out a why, shrug and move on
 
 
2 hours later…
1:55 PM
im trying to print an inverse of my matrix but i get an error say last two dimensions must be square
    code:

    inv_xtx = np.linalg.inv(xtx)
ive seen examples like this for inverse
 
2:07 PM
it worked changed it to pinv
 
 
2 hours later…
4:10 PM
Yeah I'm doubting if the serial downvote script actually works
I seem to get batches of 3-4 downvotes every now and again all around the same time
and none get reversed
I don't really care, just find it funny now
 
i have 5x100 matrix but when i use "pinv" for inverse my matrix becomes 100x5
am i doing something wrong?
 
I'm looking for a collision-resistant unique identifier that's also inherently comparable. So far my experience with comparing UUIDs is wonky (I end up with just string comparison). Does anyone have a recommendation? Looking for an algorithm or data structure, not necessarily a library.
 
4:36 PM
Actually just a random number might be good enough for what I'm doing.
 
What do you mean exactly by "wonky"?
It seems to me that UUID comparison would be a lot more collision-resistant to a random number
 
From RFC 4122:
"UUIDs, as defined in this document, can also be ordered lexicographically. For a pair of UUIDs, the first one follows the second if the most significant field in which the UUIDs differ is greater for the first UUID. The second precedes the first if the most significant field in which the UUIDs differ is greater for the second UUID."

And that's what I'm doing. It feels off but maybe it isn't. And yeah you're right, UUID is extremely collision-resistant and that's why I chose it.
I think it feels off because the bits I'm comparing lexicographically come from a time-based seed, and so it's not equally likely that the second UUID that I generate will be lower or higher than the first; it seems more likely it'll be just greater, because it was created after the first. And I think that's what I'm seeing in my work; UUIDs generated further in time are usually greater. I'll investigate this more.
 
can anyone guide me on how to inverse a 5x100 matrix? nothing i tried so far gives the results i want. i need the inverse to make a hat matrix
 
I don't recommend putting hats on your matrices. They get too cocky.
 
4:52 PM
@charley its a part of my assignment :( face Recognition using linear regression
 
5:20 PM
@charley why not just the timestamp then? I'm having a tough time why lexicographic ordering is important with having unique identifiers
 
5:38 PM
@KhwajaHussamQuasmi an MCVE would help, as always
it helps if you understand linear algebra, though
 
thank you
 
@KhwajaHussamQuasmi what library are you using?
 
@roganjosh I don't want to compare time-based encodings because I want all codes to be uniform in the chance of being less than or greater than each other. I'm going to see if that's really what I'm doing.
 
@AaronHall see few messages above: last code attempt was np.linalg
 
wim
@RoadRunner-MSFT you gotta pump those numbers up, those are rookie numbers
 
5:45 PM
@KhwajaHussamQuasmi so you can't have a proper inverse of a non-square matrix, just a pseudoinverse.
 
import sys
import os
import glob
import random
from PIL import Image
import numpy as np
 
@AaronHall the pniv converts my normalized 5x100 matrix into a 100x5 matrix with that output i cant make the Hat matrix
 
the linear regression model is something like y = Xb. to solve for the theoretical betas, you use the pseudoinverse of X, which is (X'X)^(-1)X'
(X'X)^(-1)X'y = (X'X)^(-1)X'Xb = b
The dimensions of (X'X)^(-1)X' are going to be inverse of the dimensions of X
 
I presume prime denotes a transpose or adjoint here, but that's not a notation that I've seen elsewhere
 
5:49 PM
yes, I've seen it used at FSU and Baruch.
now Xb -> predicted values for y (indicated with a caret symbol over it - so it is sometimes/usually called y-hat)
 
@AaronHall the problem here is X is normalized matrix of 5x100 (5 image matrix (training images))and Y is 1x100 (random test image) but the pniv makes X into 100x5 on which my other equations will give me an error if i run it
 
So X(X'X)^(-1)X' is the projection (or hat) matrix, which when premultiplied times y gives you y-hat. X(X'X)^(-1)X'y = Xb = yhat
I don't know if that's enough for the rest of the room to be able to help you, but I have to go now! :)
 
@AaronHall it is very helpful bro. i really it appreciate it
 
@AaronHall if I wanted to dump out-of-context linear algebra on them I could have done so myself. But you do you.
 
Well I figured the rest of the room might like the exposition. I did not solely do it for Khwaja's benefit.
 
6:10 PM
@AaronHall :) and i really appreciate it though im still stuck on the inverse but ill come through. This is actually my first python assignment
 
6:41 PM
Hello,
 
@Teixeira66 1. please see our code formatting guide to chat and practice in the sandbox if necessary. 2. you have a fresh question on main with an accepted answer that seems to be the same problem. We ask that you don't ask for help here with fresh questions as per our rules
If your question is not solved by the answer, don't accept it yet. And instead of posting code in comments, edit your question.
 
Andras Deak OK.
Got it.
Very useful
 
umm... have we got a decent dupe for this ?
 
found one
 
7:05 PM
what is about
for x in liste:
    liste.append(x*3)
that its melting my 16 gb of ram `?
liste = [1,2,3]
 
an infinite loop and an infinitely expanding list
 
thats not good :)
 
You first have 3 items. You start looping. In the first you append 3 to the list, which now has 4 items. In the second iteration you add 6 and have 5 items in the list. By the time you expect the loop to stop (after iteration 3) your list has 6 items, so the loop keeps on going. And so on.
 
@roblox what are you actually trying to do there except stress your machine out? :)
 
@roblox It's always a bad idea to append/remove items from a list while iterating over the list. One common solution for this is to iterate over a copy. Are you aware of how names and mutation work in python? If not, read nedbatchelder.com/text/names.html to understand what's going on.
 
7:10 PM
@JonClements unintentionally :)
@AndrasDeak I wanted to rebuild a list comprehension to a "normal" for loop what turned out to be a cpu stress test
 
@roblox rewriting a list comp to a normal loop involves predefining an empty list that will be your result
You are guaranteed to end up with a new list from a list comp, so the first step is always defining something like result = [] before the actual for loop.
 
 
4 hours later…
11:20 PM
Nov 19 '18 at 21:18, by Andras Deak
Apr 19 at 20:12, by vaultah
Dec 5 '17 at 8:50, by Arne Recknagel
@AhmyOhlin If you want to format code in a post, press ctrl+k, or see the code formatting guide for more info: https://chat.stackoverflow.com/transcript/message/40291589#40291589
anyway your problem is sopython.com/canon/22/…, see the linked questions
 
11:39 PM
quick question, other than open or exec, is there a way to read a file?
 
exec?
 
yeah like you call something from within exec
 
I think there's some confusion here...
 
 while (Rechenart != "+") or (Rechenart != "-") or (Rechenart != "*") or (Rechenart != "/"):
    print("Bitte Ihre Eingabe überprüfen")
    Eingabe()

How can I make this code shorter. I didn't find accurate answer in linked link
 
the third link in the linked link tells you how you can do that
 
11:44 PM
@AndrasDeak if you were denied access to open(), then technically you could circumvent it by using exec if you could
 
@aadibajpai And what would you put inside exec?
I'm starting to think this is an xy problem
 
true, for context, I was trying out a problem where I'm basically in a sandbox with access to just a few functions. Using others get blocked, and the goal is to read something like flag.txt. So I was wondering what all I could try 🤔
 
It works now. Thanks for pointing me out to the right link andras

     while Rechenart not in ("+","*", "-", "/"):
        print("Bitte Ihre Eingabe überprüfen")
        Eingabe()
 
Argh, I got it, nvm!
 
@AhmyOhlin If you can guarantee that Rechenart is a single character you can shorten that to while Rechenart not in "+*-/"
if it's not guaranteed that it's a single character then you can't do that, since '+*' in '+*-/' gives you True
 

« first day (3507 days earlier)      last day (1442 days later) »