« first day (2325 days earlier)      last day (2614 days later) » 

12:13 AM
wat? :D
 
suspend (mostly?) unrelated to the dark top nav bar theme:D
comments around here
 
user6568562
@AndrasDeak I didn't know SO had its Pentagone
 
does it?
 
12:59 AM
Hey guys Im having a lot of trouble understanding how this works ```>>> x
array([1, 2])
>>> y
array([[1, 2],
[3, 4]])
>>> x.dot(y)
array([ 7, 10])```
Can someone please tell me how the answer is [7, 10]
 
it's a product of a matrix with a vector from the left
(v*M)_i == sum_j v_j *M_{ji}
 
Why wouldn't it then be [ 1*1 + 2 * 2 , 3*1 + 4*2]?
which is [5, 11]
 
because that's not how matrix products work
1 min ago, by Andras Deak
(v*M)_i == sum_j v_j *M_{ji}
(v*M)_1 == v_1*M_11 + v_2*M_21
1*1+2*3==7
doesn't get any plainer than that
what you thought it should be is M*v, a product from the right
matrix multiplication is famously not commutative
 
haha ok I see I thought i could use vector matrix multiplication. But now I see I must use matrix multiplication
Now that I know that I can look up an explanation. Thanks
 
you can use vector matrix multiplication, but from the left side
vector-matrix multiplication is matrix multiplication
it's just that a column vector is an n-by-1 matrix, and a row vector is a 1-by-n matrix
 
1:13 AM
I see
when I do y.dot(x) though it does give me [5,11] does that mean it converted it into a column vector?
 
no, yes
1d arrays in numpy don't have an orientation, so np.dot interprets them as it makes sense
compare np.dot(x,y) and np.dot(y,x) which is what x.dot(y) and y.dot(x) are equivalent to, respectively
if you turn your vector into an explicit row or column vector (I mean a 2d array with one of the dimensions having size 1), it only works either side, and the result is a 2d array of appropriate shape
>>> np.dot(x,y)
array([ 7, 10])
>>> np.dot(y,x)
array([ 5, 11])
>>> np.dot(x[:,None],y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: shapes (2,1) and (2,2) not aligned: 1 (dim 1) != 2 (dim 0)
>>> np.dot(y,x[:,None])
array([[ 5],
       [11]])
>>> np.dot(y,x[None,:])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: shapes (2,2) and (1,2) not aligned: 2 (dim 1) != 1 (dim 0)
>>> np.dot(x[None,:],y)
array([[ 7, 10]])
it's fairly straightforward
(unlike np.dot for multidimensional arrays; that's crazy and I always use np.einsum instead)
 
Ya pretty cool thanks! @AndrasDeak
 
no worries
and with that, good night:)
 
 
2 hours later…
3:11 AM
hey
 
 
4 hours later…
7:29 AM
@JonClements
Removing the reason was the wrong thing to do, better to remove just the words "asking for homework help". — Ben Voigt 3 hours ago
 
8:03 AM
This is not an answer, this is 3rd answer here (2 others now deleted) copying my comment and posing it as an answer. — Antti Haapala 8 secs ago
 
9:00 AM
cbg 0/
 
9:24 AM
Cbg
 
 
1 hour later…
10:49 AM
cbg
 
cbg
 
\o @Andras
 
11:08 AM
I am familiar with Doxygen, but what the most popular documentation generator for Python? For example, I've seen the documentation of Matplotlib: github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/…
On the site is written, that the documentation was created by Sphinx, but I could not find what standards for code documentation is used (the style of commentaries and etc)
 
11:36 AM
Thanks man. It worked. can you explain your code ? — Sriram R 1 min ago
sigh
 
11:48 AM
@AnttiHaapala I don't think OP intended to ask about that detail though, just about how two's complement negation works. But who knows.. — harold 6 mins ago
@harold C doesn't specify 2's complement. The question was very specifically "Why does -(-2147483648) = -2147483648 (at least while compiling in C)?" Now it specifically doesn't help much to answer: "idk, but in Java..." — Antti Haapala 2 mins ago
 
12:07 PM
I'm drawing a blank here but when I post code I was told before to post it as "CVNM" or something like that
I can't remember what the acronym was
MCV
That was it
 
[MCVE]
 
12:46 PM
Well thanks to me doing it to post a question on here I think I was able to solve a problem I was having.
 
@Tokencodingnewbie MCVE = Minimal, Complete, and Verifiable example. Also see SSCCE = Short, Self Contained, Correct (Compilable), Example
@Tokencodingnewbie That's often the way. In the process of creating a MCVE you discover the error yourself.
 
Hi @Pm2, How's your mother doing?
 
@BhargavRao Thanks for asking. She passed away ~ 48 hours ago.
 
@PM2Ring Yeah feels good, reading some source code on the topic helped me approach it a different way too, but I didn't copy it.
 
My condolences, @Pm. Really sorry to hear that.
 
12:49 PM
Thanks, Bhargav.
@Tokencodingnewbie I'm sure there are lots of examples of source code for Battleships on SO, but it is a good learning exercise to come up with your own algorithms and data structures, even if the code ends up being not very efficient.
 
@Martijn just seen facebookincubator.github.io/prophet, looks awesome. If you ever get a chance to pat any of the DS team on the back, do so from me.
Others here should look into it too (cc. @DSM @JRich)
It uses STAN and MCMC analysis under the hood which I've got a strong interest in, though I've always used pymc rather than pystan.
 
@PM2Ring pastebin.com/bf36KdF2 here is what I came up with. I was told there was a lot of copy and paste in it, but I'm not good/sure how to refactor things. I know you make them into functions to be reused, sorry if my jargon is all incorrect sometimes its hard to convey my human thoughts into logical code talk.
 
OTOH, it's good not to get too attached to your code, so if you realise a better way to do stuff you can trash the old code without too much trauma. Otherwise you can get trapped into doing band-aid repairs which make the code ugly and harder to understand, and eventually you want to throw it away and start from scratch because it's just too damn hard to hold it all together. ;)
 
Yeah i started fresh with this.
I was feeling bummed out about not making progress and kinda slacked off a couple days
 
It's definitely a good idea to take a break when you experience burnout.
 
1:04 PM
@Ffisegydd I'll pass it on! :-)
 
cbg
how do i change the color of text in a wallpaper
in photoshop
 
Hi Guys
i wanna to start a programming language and think python was good :)
 
@Ffisegydd: I asked them if there are any plans to present at PyData 2017 London.
 
1:20 PM
as you work hard on python its good idea to start for gaining too much money from python? :) or other option was better? ( just for remote work)
 
@Tokencodingnewbie I've just had a quick look at your code. It still has a couple of problems: it needs to make sure it's not placing a new ship on top of an existing ship. But you can work on that. In the mean time, I can show you how to reduce the place_twoship function to a quarter of its current size. Give me a couple more minutes...
 
Oh yeah I forgot about that part, whoops. That would be cool though, thank you. I might not be awake but I'll read it when I wake up if I pass out.
 
I don't know why you want that flippedbattleshipstwo list, but I've kept it in my code. I use the list .extend method, which is more compact & more efficient (than using the .append method) when you want to append a bunch of stuff to the end of a list.
@SohaibAsif You've got to be yamming kidding, right?
 
1:39 PM
just some non python things
but all in vain
never did the frontend work :(
 
 
1 hour later…
2:52 PM
cbg :)
 
Any ideas why i might i keep getting 500 errors when i try import another script to use in a flask app??
When i try import to another script it works fine, but wont work with flask. :/
 
Does anyone know that whether there is logstash support for syncing the data between Impala and Redis?
 
DSM
@Ffisegydd: very interesting! Many thanks for the link, somehow hadn't heard.
 
@AnonInternational Must be related to file structure of the project. You might not be doing the import in the correct way. It definitely doesn't have anything to do with Flask
@PM2Ring I am sorry to hear that.Extending my most heartfelt sympathy to you and your family.
 
Thanks, Moinuddin. My Mum appreciated your thoughts and prayers.
 
3:11 PM
Hmm, can use the imported functions fine in another test script, not sure what i'm missing here.
I am using pycharm, when i have even just the import it throws an error in the browser.
"from dbscript import connect"
works fine for any other thing i've tried >.<
 
3:52 PM
Recbg
 
@DSM Yeah it's the kind of thing I could probably do myself in code but it's an interesting looking library for quick forecasting or for people without the knowledge to do it themselves
 
4:19 PM
@ThiefMaster that Jinja namespace patch is cool, thanks for doing it!
That reminds me I need to get my small patch cleaned up too.
Currently working on the Flask-SQLAlchemy tablename bug you reported ages ago.
 
earned at least 200 reputation on 76 days
... hehe ... 49.3 % to go
 
If I sigint a python process. At what level does the interrupt happen? Are there any guarantees about what will be completed before termination?
 
Should run the normal shutdown process.
 
Yes. But what is that process?
Will the current method return first, etc?
 
What do you mean?
No, it will be interrupted, then the interpreter will shut down.
Not sure about finally blocks, but that's easy to test.
 
4:36 PM
K, I'm really wondering about sqlite3 database operations and can I be guaranteed that, say, two related inserts were completed, and not just one. I guess I'll have to use 'signal' to manually handle interrupts, right?
 
If you're using a transaction, then either both will have finished, or the transaction will not have closed before the resource is released.
 
Or that... Yeah, might be easier. thx.
 
@davidism Thought that's the fastest way of getting it done ;) and we have this template at work where the only alternative is abusing mutable objects
 
The horror!
 
@davidism for the record, I believe I can open the connection using a with statement, this will rollback anything executed within the statement if there's an exception.
 
4:57 PM
@RichardDunn sigint should result in KeyboardInterrupt being thrown
if you've got except: blocks without any filtering, they will be caught!
 
Yes! I think I figured out the Flask-SQLAlchemy tablename bug! Finally! Cabbage!
Premature celebration, since I haven't fully tested it, but still closer than any of the other attempts so far.
 
@AnttiHaapala thanks, but that would mean I'd have to manually try to rollback any operations, no?
 
5:22 PM
Oh yam. John Zelle strikes again. Yet another new Python coder has been infected with his habit of using eval stackoverflow.com/questions/42471482/…
 
5:43 PM
@PM2Ring maybe I should just edit it out of the question:D
I also find the question unclear
 
5:54 PM
@AndrasDeak The OP just doesn't understand how to calculate interest.
And if their maths skills are that bad, they are going to have problems implementing all but the simplest of algorithms.
 
This is my first time posting to this chat group. I would like to ask one simple question about counting the number of items in a list using dictionary. I use the following method to do so.
ourlist = [1,1,2,2,3,4,5]
d1 = {}
for items in ourlist:
  d1[items] = ourlist.count(items)

print(d1)
 
you can edit messages
What's your question?
 
i mean to ask if theres a better way to do in in terms of Big O
 
from collections import Counter
c = Counter(ourlist)
 
I know this is O(N) because the for loop has to go through each item in the list. Can this algorithm be improved perhaps
 
6:08 PM
It's actually O(N^2), since count goes through the whole list for each item in the list.
from collections import defaultdict
d = defaultdict(int)
for item in ourlist:
    d[item] += 1
if you can't use Counter for some reason
 
yes I can see.
 
alternatively, you could check if items is already in the dict, and skip subsequent calls to count, but davidism's solution is simpler.
 
@davidism The Big-O is still O(N^2) in your second method right ?
 
No, it's O(N) in both my examples.
 
user7327263
6:38 PM
hi guys. Below is my code when I run that it returns TypeError: 'NoneType' object is not callable
 
user7327263
TypeError: 'NoneType' object is not callable
 
user7327263
what can cause this?
 
please use a paste site for large blocks of code
 
@PM2Ring then it's wildly off topic...
BTW, when should eval be used than? — user7625952 49 mins ago
@user7625952 as a newbie in python: never. There are very rare and special cases where it's necessary, which is a good thing, since eval is very dangerous (it can execute arbitrary code for you, even malicious code). If you follow best practices, you'll almost never have to resort to using eval (as I said, with a few rare and very advanced exceptions). — Andras Deak 1 min ago
^ is the above adequate?
 
6:54 PM
@davidism I did not know about defaultdict method before. Now what I know of is that it minimizes the following code (if item not in d: d[item]+=1 ) so that even if the key does not exists, it adds 1 to the value (if I am correct)? I am just a beginner in Python and I am using it to practice algorithmic questions in my course. That is why I am in the process of learning it. I am not expert but still I know how to use lists and dictionaries. So, I apologize if my question is a bit silly.
 
note that davidism's first reply shows the most proper tool for the job, namely collections.Counter. It's exactly made for this job.
I know you're learning the basic data types, I just wanted to note this
 
okay. Thanks @AndrasDeak. These subclasses are very useful but I dont know why interviewers discourage using these tools in an interview (for college students atleast)
 
I don't know either, one of the strengths of python is the versatility of the standard library
I assume that crappy interviewers discourage them:P
good interviewers should be looking for people who will write good code, not necessarily reinventing the wheel
 
If someone I was interviewing used the standard library, that would be a plus. I'd still probably ask them to implement the underlying logic though, which the second example does. I definitely wouldn't discourage it.
 
in our university, google came to give an interview workshop, and they were strictly against allowing anyone to use these libraries during the interview
 
7:04 PM
There's a difference between relying on them and using them. If you know how they work, then go ahead and use them. Google's policies are up to Google though, I'm sure they'd tell you during an interview if they want more.
If your tripping point in a Google interview is that you don't know what Counter does, I have bad news.
 
@ShrijanAryal Because there focus would be to check for the algorithmic skills. If I interview someone for Python, I want to see the usage of inbuilt function so that if I hire them, they don't re-invent the wheel.
cbg all
 
cbg
 
Is it just my internet or everyone has to retry for posting the message? I am seeing this error very often these days
 
it's just yours
at least mine's fine
Do you always use the same tab for this chatroom? Try opening a new one in this case.
I had a problem once where this tab (out of ~400) wouldn't load, but when I opened room 6 in a new tab, it loaded fine
the tab got stale:D
 
7:08 PM
Yes, I generally use the same tab :P You suggestion actually might be helpful
 
that sounds as if you're surprised :P
 
Actually I am. It never came to my mind that I should change the tab :(
 
let's hope it helps...
 
It is working fine till now. You are awesome ;)
 
7:15 PM
This question might sound stupid. But is there a way to know how much reputation the user got because of that answer (accounting all up votes) on SO ? Could this be a better implementation to SO (if this feature doesn't already exist) so that others can get an idea of the number of upvotes required to get a certain number of reputation ? Or this might be an useless idea :P ?
 
1 answer upvote = +10 rep, or I don't understand your question
 
and also there's stackoverflow.com/reputation for your raw rep history
 
OP is happy with my eval answer
 
7:22 PM
@AndrasDeak With this I got to know that I earned zero reputation in this week :'(
 
Oh, week starts on 26/02/2017 :P
 
Me too
 
You are busy with moderation work, and I am currently occupied with office related stuff. Going back home on this Wednesday, so I had to clean up few of my pending tasks :)
 
7:42 PM
cbg
 
cbg
 
Congrats to @TheMexicanRuner on beating ALL 714 NES GAMES with a time or 3435:12:24 - PB HYPE! - The 1st person in… https://twitter.com/i/web/status/835926783342018560
Too much video games.
 
8:28 PM
@ShrijanAryal +1 for not allowing eval
 
what, 5 months :D
 
9:11 PM
Doesn't python allow to increment the index of the for loop inside one of the "if" conditions, so that the loop definition can skip some values and jump to the desired index ?
 
@ShrijanAryal try setting the loop variable inside a loop for a dummy case and see what happens
 
gist: A confusion related to index of for loop. , 2017-02-26 21:17:56Z
'''The code is meant to skip adding the character "a" and any other character that comes after "a". For this, I check if string's [i th] index = a, and add 1 to index, so that new index will be able to skip the character coming after "a". But this does not seem to be happening. Why is it so ?'''

str1 = "abcde"
str2 = ""
for i in range(len(str1)):
  if str1[i] == "a":
    i +=1
    continue
  else:
    str2 += str1[i]
print (str2)

#Output is bcde. But why ?
basically this is my question
 
even if it were possible (it is), messing with indices like that is never useful/clear
just use an if+continue
 
@ShrijanAryal BTW you do not need index for achieving this. You may write the same logic as:
>>> str1 = "abcde"
>>> str2 = ""
>>> for x in str1:
...     if x != 'a':
...         str2 += x
...
>>> str2
'bcde'
 
btw I think your loop accidentally does what you want it to do...
 
9:21 PM
^ And yes, your code does what you want. Isn't it?
However the line i +=1 is not doing anything there. You may remove it.
 
no. i meant to skip "b" too. that is why i incremented i by 1 inside the if statement. So that, index would be 0 (originally) and 1 (because i did i += 1 inside if statement). Lastly i wanted the index to be 2 because of the loop definition (for i in range(len(str1)):). So, by this way, i wanted the index to be 2 so that I would skip "b"
I thought that it would work that way
 
but it doesn't
 
because i am increasing index inside the if statement and again by the function definition.
why ??
 
7 mins ago, by Andras Deak
@ShrijanAryal try setting the loop variable inside a loop for a dummy case and see what happens
you'll need to work on this
 
because when control goes back to the for loop, the value of i is reinitialized
 
9:26 PM
(and even if it didn't: i is an int, so it's immutable; but this is an irrelevant subtletly)
 
If I were you, for achieving this I would have used regex. But I think it is not something you are looking for.
>>> import re
>>> re.sub('a\w', '', str1)
'cde'
 
10:12 PM
@Orange good news:
 

« first day (2325 days earlier)      last day (2614 days later) »