« first day (3653 days earlier)      last day (1299 days later) » 
05:00 - 20:0021:00 - 23:00

5:28 AM
cbg
so much math stuff last night over here, glad I slept :D
 
 
1 hour later…
6:34 AM
@roganjosh I appreciate
 
 
2 hours later…
8:39 AM
is there a better way to do the following?
def group(seq,size):
    return list(zip(*(seq[i:] for i in range(size))))

t=[1,2,3,4,5,6,7,8,9]
print(group(t,2)) # [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9)]
print(group(t,3)) # [(1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5, 6), (5, 6, 7), (6, 7, 8), (7, 8, 9)]
unrelated but I hit 100 rep today, long way to go :)
 
@python_learner if memory is not a concern and you always have sequences it's probably fine
 
I just converted that zip to list for printing purpose, its for a code site, so I am guessing they have memory limits
 
a general solution might need itertools.tee(seq, n=size)
@python_learner it's not the list, it's the size copies of seq (unless it's something smart such as a numpy array)
 
I read the docs, and tee makes copies of the iterator, seq in my case, so I have to use islice(copy_1,1) and islice(copy_1,2) so on?
 
yes
 
8:47 AM
ok I have a question then, zip is lazy? how is tee better then?
 
@python_learner zip is lazy, but when you do zip(*(seq[i:] ...)) you instantiate all those seq slices by the time zip gets a chance to yield from them. In contrast,tee is smart and reuses fewer items in the input sequence.
zip's laziness doesn't magically make all those lists go away which zip yields from
 
that makes sense, thanks
also why is it called tee any reason?
something alone the lines of copy would make it more obvious
 
@python_learner probably because by default it splits in two, and there's a linux utility called tee that takes standard input and makes a copy of it into a file, meanwhile sending it forward to the eventual stdout. My guess is the name comes from there, but I don't know why the linux tee is called tee
@python_learner you will probably need islice(copy_1, 1, None) or something though
 
ahh ok, will check islice docs as well, as for tee I will google linux tee then :)
 
"gnu tee" or "gnu coreutils tee" is probably better
@python_learner if you're done, here's how I'd implement this: view spoiler
 
8:54 AM
hope the expiry is set for at least a day
I might need a while if I mess up
 
the data is in the URL, it won't expire
you can take your time
 
I thought it was pastebin
 
nope
 
thanks, always better to know pythonic ways
 
can't guarantee that :P
 
8:55 AM
laruel, better than my pythonic ways at least
t=[1,2];t[1:];None in this, t[1:] takes some memory right? when it comes to None does the memory released by then?
asking this so I can relate this with how zip works, thought it was related to what I asked
 
I'm not quite following how None comes into play here.
Do you have a single statement "t=[1,2];t[1:];None"?
 
its just to denote the next line, I didnt want to write a three line snippet
it could be anything, I just wanted to show that there is some op after the slicing that doesnt depend on the previous lines
 
Given strict evaluation, ;None would take up some memory for the bytecode and its evaluation.
On current versions, this is stripped away during compilation, though.
 
the memory for t[1:] stays for only that line unless its bound to a name?
 
Hi guys, will using python be a good choice to bulk update something stored in mongodb?(records are ~45k rows)
 
9:10 AM
@python_learner That depends on the memory management scheme. So in CPython, yes.
 
cant you just use mongodb queries directly?
@MisterMiyagi thanks
 
I can but I am new to this and I have a time constraint , thats why I was asking
Would be also helpful if there is any room dedicated to mongodb that you can direct me to
 
idk mongodb but update can be easy to find online, sorry :( , I just come here once in a while, regulars will help you
you can try the python discord server, they are flexible than here, but that comes with its own problems
 
@RaphX unless you need to do some serious, custom number crunching, Python is usually an adequate choice.
 
9:55 AM
@AndrasDeak this is what I ended up going, similar to yours, but other than yield from
def group(seq,size):
    return list(zip(*(islice(copy_,idx,None) for idx,copy_ in enumerate(tee(seq,size)))))
 
@python_learner that's fine, but 1. not very readable, 2. not lazy
 
list?
 
yes
 
its still there for debug/print purpose, but yeah could break it down
 
If you want the function to be lazy, call list on its output for debugging/printing
 
10:00 AM
in that case both yield from zip... and return zip... would be the same?
but now you know why I said better pythonic ways :p
 
@python_learner yes, yield from zip would make the function itself a generator function. return zip will return the zip object itself. I guess yours is probably even better, because there's one level fewer in the call stack.
 
I am reading this to get a better understanding stackoverflow.com/questions/41136410/…
 
basically yield from zip would wrap the zip for no good reason
 
@AndrasDeak It's called tee because in software terms the tee utility is like a t-joint in a plumbing pipe: one input goes to two outputs. The analogy doesn't hold quantitively, of course, since twice as much goes out as comes in, which would break the laws of conservation.
 
@holdenweb ah, makes sense, thanks
fits the pipe imagery
 
10:12 AM
Quite so.
 
so @python_learner's case for n=3 could be called ecks
 
laurel, wikipedia's article for tee also has the same reason as pointed out by holdenweb
 
An enlightening representation of that code is shown in this pythontutor link (had to shorten it) where you will see no data structures. Sadly PythonTutor can't trace generators :-(
 
is it supposed to have nothing in the code area?
 
11:01 AM
Oh dear, looks like bitly hosed the link. Never mind ...
I simply wanted to point out the generators, but that lack of tracing limited my scope somewhat ...
 
@holdenweb what do you mean "trace"? Wouldn't that involve next(x)?
 
11:36 AM
Hi everyone, I tried to connect to mongodb using python but I am getting a ServerSelectionTimeOutError
The funny thing is when I connect using Robo 3T it connects without any problem with the same creds
I have double checked the creds and they are exactly the same
Any idea whats happening? I am kind of lost
 
79
Q: Downvotes Survey launching Oct 15

Anita TaylorStarting tomorrow, we are launching a survey to gain insight into why users downvote questions and answers on Stack Overflow. When you click the downvote button, you may see an invitation to take the four-question survey. Please note, we are not seeking feedback on the survey methodology or quest...

SE trying to increase downvote rates by offering prizes :P
 
 
1 hour later…
12:54 PM
@AndrasDeak Still haven't triggered it yet... :/
@RaphX We cannot really help you without knowing what you have actually done.
 
if at first you don't succeed...
 
On it...
 
morning cabbages, folks
 
Hello
Anyone, who has more than one audio output in the computer?
I want to test some code.
 
1:11 PM
as in, stereo?
 
... or do you mean"more then one audio output" as in "my computer's default speakers /and/ my wireless headphones"?
 
Why are you writing code for something you can't even test? That screams "bad idea"
 
Chris P has a non-trivial asking record...
 
Hi everyone. Can I ask a question to someone regarding clustering algorithms in python.
specifically abour K-Means clustering
*about
 
1:20 PM
@Destroyer-byte you've read the rules, haven't you? :P
@Destroyer-byte and you can edit/delete messages for 2 minutes in chat
 
yes bro, I have. Thank you for the manual.
oh, how do I edit a message?
ah, i see. I have found the option.
Regarding Clustering Algorithms in Python, I Understand that they are unsupervised algorithms, however, what is the nature of the data-type that they are used to predict?
 
@Destroyer-byte what do you mean by that?
You need a graph for clustering. The graph can also come from objects that have a distance defined among them. That's my naive picture.
Or I guess the graph is not fundamental, you can probably cluster using continuous distances. In any case you have to quantify how data points relate to one another.
 
For example, Linear Regression- we know that the target vector in a linear regression algorithm needs to be of numerical data type. Similarly, is there a specific data type that I am limited to predicting when using K-Means Clustering?
yeah a graph is useful for clustering.
 
Technically you could do linear regression with anything that can be mapped to numbers, it's just that implementations are rarely that general. But if you had a dataset as a function of datetimes you could do curve fitting on it.
 
oh. I have not learnt about curve fitting in detail as yet.
maybe in my modules to come.
 
1:29 PM
Linear regression is a kind of curve fitting
Anyway, you have to separate theory from implementation.
 
Ah I see.
Yes bro. I am new to IT- I started studying it this year, and I have learnt that the best way to do coding, is to physically experiment.
 
that certainly helps, although it should be coupled to looking at documentation, and reading tutorials in the earliest stages
(and copious amounts of googling)
 
For K-Means clustering, I tend to get a little confused though. Because, I mean, I load my data, split into features matrix and target vector. I then standardize my features matrix using StandardScaler. I obtain the Elbow Graph using the within-cluster sum-of-squares, which helps me select a value for K. I get a little muddled during the prediction and visualizing stages.
 
my two cents' worth: any problem in a space with a distance metric defined between any two data points can be clustered
 
yeah bro, you are correct, documentation helps a lot
 
1:34 PM
what do you mean by "within-cluster sum-of-squares"?
 
@inspectorG4dget this makes sense bro
 
@inspectorG4dget the "sum of squares" between the items in a cluster. Intra-cluster distance.
 
The inertia
Can I please send a small question through? It is something I would like to have a little more insight about.
 
@MisterMiyagi is the sum of pairwise distances between all pairs of points in a cluster? That can be argued to not be the best cluster-quality metric
 
@inspectorG4dget there is no best cluster-quality metric, so you can argue that for every cluster-quality metric :P
 
1:37 PM
touche
 
Will it be possible?
 
@Destroyer-byte welcome to Room6. Just ask your question, and if anyone's able to help, they'll speak up. It's pretty impossible to know whether we can help before knowing the question
 
Thanks bro. I will do that.
how do I leave a line in my message?
 
please check out the code formatting guide, and take the time to practice in the sandbox a tad
 
It will be a very easy question for you guys. I made a small dataframe to assist myself in seeing the logic behind the K-Means, but just visualizing it and understanding predictions confuses me.
thanks for that Mister, I will view it now.
 
1:42 PM
can I let it be known that I identify as not a "bro". I use he/him pronouns, but "bro" just doesn't work for me, for some reason
 
Sure. I will refer to you as Inspector if that is fine with you?
 
well, that /is/ my name :)
 
😀
import pandas as pd

dataframe = pd.DataFrame({'age':[18, 19, 6, 5, 7, 20, 5, 6, 7, 8, 18, 19],
'weight':[66, 70, 35, 30, 40, 71, 34, 39, 43, 44, 63, 67],
'drive':['Yes', 'Yes', 'No', 'No', 'No', 'Yes', 'No', 'No', 'No', 'No',
'Yes', 'Yes']})

print(dataframe)
print(' ')
 
celebrates MCVE of a first-time poster by pasting it into a Ruby shell
 
that is a simple dataframe that I have created today, in order to assist myself in understanding K-Means Clustering. I have split the dataframe into features matrix, and target vector. I will use the algorithm in order to predict whether or not an observation is able to drive or not.
features = dataframe.iloc[:, 0:2]

target = dataframe.iloc[:, -1]
I have thereafter Standardized the feature values using StandardScaler from sklearn.preprocessing
from sklearn.preprocessing import StandardScaler

features = StandardScaler().fit_transform(features)
I viewed a few characteristics about the matrix and vector, and thereafter printed it out.
print(features.shape)
print(target.shape)
print(' ')

print(features)
print(' ')

print(target)
print(' ')
Before creating an instance of K-Means(), I made use of a for loop, to create an iteration that would allow me to see the effect of K.
from sklearn.cluster import KMeans

within_cluster_sum_of_squares = []

for i in range(1, 11):
    technique = KMeans(n_clusters=i)
    technique.fit(features)
    within_cluster_sum_of_squares.append(technique.inertia_)

print(within_cluster_sum_of_squares)
print(' ')
The next step was for me to visualize the data. I used the matplotlib.pyplot library.
import matplotlib.pyplot as plt

x_axis = range(1, 11)
y_axis = within_cluster_sum_of_squares

plt.plot(x_axis, y_axis, label='Algorithm Effect', color='blue')
plt.title('K-Means Elbow Graph', color='blue')
plt.ylabel('Within Cluster Sum Of Squares', color='blue')
plt.xlabel('Number Of Clusters', color='blue')
plt.legend(numpoints=1, loc='best')
plt.show()
I am unable to send the image, however, the line graph conveyed to me, that a value of K = 2 would be most appropriate for the model.
 
1:56 PM
@MisterMiyagi Hey its ok now, thank you! My IP address changed causing the authentication problem. I guess thats why one should study CS fundamentals.
 
Thereafter, I made use of my choice of KMeans, and set n_clusters=2
technique = KMeans(n_clusters=2)
And this is the point, at which I have a few questions.
I used my instance of KMeans() to predict values for my features as such:
predictions = technique.fit_predict(features)
Question 1: The predictions that I obtain, are using the 'features' variable (features matrix) in order to predict? (Y/N)
 
I do have a doubt related to mongodb though which I haven't been able to solve. If anyone knows mongodb, I shall ask otherwise I won't as this is a python room.
 
Thereafter, I have viewed the labels of the model.
print('The Labels That Are Available For Prediction: \n'+str(technique.labels_))
print(' ')
 
I think you should use kaggle to get the basic idea of the models. There are also a lot of MOOCs @Destroyer-byte
 
Question 2: What are those labels that the model has predicted? Have those labels been obtained through the fitting process?
Yes Raph, you are correct, I have enrolled in a few courses, but they do not explain a few of the aspects at times.
It is mostly the Visualization aspect that gives me an issue. Because I have wondered if there are other techniques to view the distinct clusters.
For example...
plt.scatter(features[predictions==0, 0], features[predictions==0, 1], color='crimson', edgecolors='black', label='Data_Points')
plt.scatter(features[predictions==1, 0], features[predictions==1, 1], color='silver', edgecolors='black', label='Data_Points', marker='o', s=None)
plt.scatter(technique.cluster_centers_[:, 0], technique.cluster_centers_[:, 1], marker='d', color='yellow', edgecolors='black', s=100, label='Centroid')
plt.title('K-Means Distinct Cluster', color='blue')
plt.ylabel('Weight', color='blue')
That was the code I required to visualize two clusters in this problem. My question is, is there not a more efficient method to visualize all clusters on a single graph, instead of using boolean logic to plot the distinct clusters?
Because I have done a problem that contains 6 clusters, and the code required to plot the distinct clusters and data points belonging to each, is relatively long as a result of the approach using the comparison operators.
 
2:12 PM
@Destroyer-byte prediction with k-means is a pretty primitive operation. it will just look for the nearest mean for each data point. Since fit_predict(x) is fit(x) followed by predict(x), it is basically telling which cluster each feature belongs to.
So yes it uses the features because that is what you are asking it about.
 
@AndrasDeak Well, duh ... I guess so!
 
Oh I see Mister.
Thank you Mister
 
@Destroyer-byte the general answer is "use a loop", in which you would parameterise the plot command by e.g. the data or mask index. For example, for i in range(6): plt.scatter(features[predictions==i, 0], features[predictions==0, 1], color='crimson', edgecolors='black', label='Data_Points').
The specific answer is that Matplotlib and many other plotting libraries support sending them multiple data series at once, however. Check the docs for the desired plotting function whether it supports this.
 
@MisterMiyagi, thanks a lot 🙏. Your approach is really good
I will check the docs
I am going offline for now. Thank you for the assistance.
 
3:34 PM
@inspectorG4dget I'm curious on your take for "mate" :P I also don't like "bro" and I think that probably comes from tv/film depictions of the people using it. But "mate" is really common where I'm from and I exploit it a lot because generally I can't remember someone's name for like 6 months. My memory confuses me on that point - I can remember so many abstract things but I've forgotten ~50% of names before they even finish the next sentence :P
 
MisterMate agrees with roganmate!
 
"Hey Josh" --> "hey, y'alright mate?" --> <mental fist pump> "nailed it again"
 
"MisterMate" is almost like an oxymoron. Shouldn't it be "MateMiyagi"?
 
3:50 PM
"Mister" is the first name :P
 
@roganjosh Way to tell people they aren't important ;-). Have you ever searched for "how to remember names"? The easiest way to remember them is to use them a couple of times soon after the conversation begins. Set-dependent memory does a lot of the rest.
Apropos other recent posts, I now wonder if @roganjosh is actually a josh of the rogan variety.
 
@roganjosh "mate" always reminds me of "crikey mate!", which makes me smile. So I don't dislike it, and am open to it. For whatever reason, "bro" makes me feel like I'm being called a gym-bro/meathead/all-brawn-no-brains guy, which I know was never the intent, but it directly makes me feel like I'm being thought of as an idiot
inspectorMate agrees with roganMate
 
4:11 PM
in India at least where I am from, it is common to call people bro
mostly if you dont speak the same language as they do and converse in English
 
@holdenweb That's why I have really worked on it because that's not the meaning behind forgetting names at all - I can remember faces after just the slightest engagement from years ago. If I know someone with the same name, I try to build an association between the two people. But it's not even an exaggeration that names are gone from my head by the next sentence and I have no idea why
 
My sister suffers from face-blindness (prosopagnosia). You might want to take the test at openpsychometrics.org/tests/EBFMT if it causes you concern.
 
@inspectorG4dget I can't be sure, but I could probably count the number of times I've said crikey on one hand :) I suspect it was a British word that the Australians subsequently ran with but I now I'll have to etymologise it to see who used it first :)
@holdenweb It's only a concern in-so-far-as your observation - it does seem like I'm disregarding the person. It's not something that keeps me up at night, though :P
 
> in India at least where I am from, it is common to call people bro
This is very true, and is why I have a hard time when I go back home
 
"Believed to have its origins in 19th-century Australia, where it was originally uttered as a way of expressing surprise or dismay." huh, it looks like we might have taken it from them, then
 
4:20 PM
@inspectorG4dget mind asking where you are from "bro" :p
 
@python_learner Chennai. How about yourself? ;)
 
close to Chennai, Madurai :)
ngl, first time seing a ~100k Indian rep user
 
Madurai is awesome. Been once... love it there!
oh I've been here for... a while, and one very fortunate question
 
its an old fashioned place, but yeah it has its perks
 
What's the deal with this question? stackoverflow.com/questions/60471865/…
12,000 views, no votes
in 7 months
Because of the link in my answer, it got me a bronze, silver, and gold medal. Yet my answer has zero votes and is otherwise virtually invisible
 
4:26 PM
woah, 12k views?
 
Maybe it's a popular question in HackerRank, with people who don't have an account?
 
Complete speculation - they refer to a book that is introducing python. The author released a new version and referenced the question... but all the viewers have no SO rep because they're beginners so they can't vote
 
@NicolasGervais gimme the codezz rarely gets upvotes – it's a wonder this thing is not DV/CV'd mercilessly.
 
Err, not a book, datacamp? It's hard to tell what "Practice to Learn Python" is
 
but I guess people doing the same challenge/book will find it a lot.
 
That's reasonably-aligned with my original hypothesis so I think something at least along those lines has happened
 
I downvote it anyway and added a comment suggesting others might like to. I'll probably get banned for incitement now. :-) (Always was a troublemaker).
 
Look at the rep of OP. It's a combination I've never seen
1 rep, 2 gold, 2 silver, 3 bronze
 
4:46 PM
ok the question is highly visible, probably because of its homework-y nature That explains the 2/2/2. The third bronze if from having taken the tour
 
@PaulMcG is that.... a named lambda?!!!
 
Realpython loves 'em
 
Oo, oo, tell that story again about the origins of lambda, MM! <snuggles into duvet> :P
 
Waaaaaaaargh!!!!!
 
And I wonder why I have a complex....
 
4:59 PM
SO main does that to you... :P
 
Actually, fair. I guess if you were to package up the main feed in some carton, it'd have "Waaaaaaaargh!!!!!" in comic sans at a 45 degree angle up the side
 
[[{'varVals': {'X': 3},
   'subtopicId': '0ef70af9-804e-496a-a2da-f4100fddec49',
   'options': ['3:1', '1x5'],
   'topic': 'gridbuttons',
   'inputMethod': 'done',
   'id': 247431,
   'categoryIdQuestion': [''],
   'templateid': '9baf9f70-45ac-4b0a-8d67-1b1dcc5a20d7',
   'answer': [0],
   'mathRep': None,
   'categoryIdVh': ['']},
  {'varVals': {'X': 4},
   'subtopicId': '0ef70af9-804e-496a-a2da-f4100fddec49',
   'options': ['20:1', '8:2'],
   'topic': 'gridbuttons',
   'inputMethod': 'done',
   'id': 247432,
Hello everyone, I have a column that I imported from mongodb in python which is having values as above
I intend to update ':' with '/' symbol inside options sub-field for every subtopic
How do I do it?
The data is much more bigger so plz share a scalable solution if you know any
 
Do you have any solution currently?
 
No @roganjosh
 
Have you tried to implement a solution?
 
5:07 PM
Yeah but couldn't make it work
 
Ok, well can we start with what you tried, please? If it's a long block of code, please post on something like dpaste and link here
 
I was just trying to view it before doing the change so my code might not help much
let me still link it
 
@MisterMiyagi, thanks a lot for the assistance earlier
 
Here you go @roganjosh
 
(It's not just for me btw. I actually very rarely use Mongo)
 
5:15 PM
I just learned it and already got a tough assignment :(
 
Ok, so you haven't actually tried to replace anything. The answer to my question of "have you tried to implement a solution?" is actually "no"
 
I guess not because I am not to filter it
 
@RaphX Your second loop should be for record in range(len(values_to_change[sublist])): instead of for record in range(len(values_to_change[0][0])):.
But note that you can iterate directly, e.g. for record in values_to_change: for sublist in record: and so on. record and sublist will be the (nested) lists in this case.
 
I suspect there needs to be some smarts behind the alteration to minimise transactions. Or, you actually are familiar with Mongo and I'm off the mark :)
 
@roganjosh To whom you are telling? @roganjosh
 
5:19 PM
MisterMiyagi
@RaphX Fundamentally the data is just a JSON structure so there really is a huge body of pre-answered questions on how to manipulate that
 
@MisterMiyagi Ok I see now, thanks!
@roganjosh Ok I will need to learn up on that then
Could this task be done in an easier way rather than the way I am doing?
 
@roganjosh I assume it's an actual list/list/dict parsed from JSON, which will be dumped back to Mongo after modification.
 
If I may ask, to get to know everyone better, How old are you guys? Also because you all are much more experienced than I am in Python.
 
Yeah thats true, I need to update the values and dump them back
 
If it's a one-off task, optimisations probably are not worth the added development time.
 
5:26 PM
@RaphX You aren't doing the task, so it's not possible to give a "better" approach without getting inf values in trying to quantify the improvement. The point I'm making, and which you took with "Ok I will need to learn up on that then" (thanks!), is that you are actually hampered by using the room as a solution factory
@Destroyer-byte 7 and 3/4
(Actually 33 next month) :)
 
@Destroyer-byte I start school next week.
(Actually 70).
 
Wow @roganjosh. Can I refer to you guys as 'bro'. By nature I do not like calling people by name.
@holdenweb, 70 years?
I am 18.
 
What other units would I likely be using?
So I suppose you'll want to call me grandaddy or some suitable abrv.
 
@holdenweb, haha, no not at all. Bro will be perfectly fine for me.
 
@Destroyer-byte You can refer to anyone however you wish, you just can't expect that they'll be happy about it (and obviously offensive terms will get removed) :P I personally don't like "bro" either but it's not a big deal
 
5:31 PM
Calling people by the name they recognise is as easy as replying to a specific post.
 
Ah I see. No stress @roganjosh.
 
I'm not stressed :P
 
@holdenweb, yeah bro, I usually include the name and 'bro' in the same statement.
@roganjosh, 👍
I am new to IT. I started this year.
 
I personally don't see the need to use any designation. Using "bro" at the end of a sentence is even worse than using the name, bro.
When in Rome might, perhaps, apply, bro?
 
So I shall refer to the people by names, just to be safe.
 
5:34 PM
Off out for dinner now - Friday night is date night, after all.
Rhubarb, all. Have an enjoyable weekend.
 
@roganjosh PEP8 isn't so much a rule, it's more of a guideline.
 
@holdenweb, you as well.
 
If you print it out and roll it up it's also quite useful for smacking offenders updside the head! [leaves]
 
Bye @holdenweb, Enjoy dinner and the weekend.
 
@roganjosh Point taken! I did the replacement , thank you!
 
5:37 PM
@PaulMcG sure, I was half joking. I didn't go out and start ancient rituals lest Cthulhu was coming down :) But given the context of the question - beginner - (and the number of views!) I'm not sure it's a good idea to be breaking PEP8 because they don't have context to judge whether it's right
 
I voted to close the question because I think this is not a good use of SO. If the tutorial site wants to support student submissions and discussions of their study problems, they should do so on their own site (which would also give them better control over the quality of posts).
The poster's other question is also from that same study site. It has been closed, and I just voted to delete.
 
@MisterMiyagi it's an actual Mongo record, no? It seems more likely a page/sheet/whatever-they-call-an-entry
 
for i in range(0, 3):
    plt.scatter(features[predictions==i, 0], features[predictions==i, 1])
plt.show()
how can I add color to change each time the loop executes
I have tried additional lists and list comrehensions, but I get len() errors.
 
Have you looked at how to set colours on plot data?
 
Does it require that you spell "colors" with a 'u'?
 
5:45 PM
Yeah. I know how to set the colors, but am having a little difficulty including it into the for loop
@Paul, the keyword argument spells it as 'color'
 
@PaulMcG no, sadly not :(
 
Ethnocentric jingoism strikes again!
 
@Destroyer-byte what was your additional list approach?
 
I defined a list called colors = ['red', 'green', 'blue']
and I included another for loop:
for color in colors:
 
Ack. You had a perfect start but there's no need for a second loop
 
5:48 PM
Ah I see.
Then I also tried list comprehensions
 
@Destroyer-byte - instead of a for-loop, wrap your list in a itertools.cycle(), and just keep getting the next color from the returned iterator.
It will cycle through the list and repeat if you need more than 3.
 
@Paul, that sounds good. Could I request you to guide me through doing that?
 
for i in range(0, 3): is giving you a list of indices. (There's no need for the initial 0 btw) so you can use the value of i to index multiple lists within the same loop
 
@Rogan, I will remove it.
 
Anybody have any hints on imposing additional, custom, requirements on certificate authentication for TLS? I'm using requests (urllib3) at the moment, but I'm open to switching to something else if its not possible otherwise. I'm thinking I have to add a callback into the (ssl) context somewhere and do my extra checks there, but I'm not seeing much information anywhere.
 
5:50 PM
I usually include it all the time though.
 
I'm hoping I'm just googling the wrong things and somebody has done similar before, but I can always write up a real question....
 
color_getter = itertools.cycle(colors)
for i in range(0, 3):
    next_color = next(color_getter)
    # do whatever is appropriate to use the new color
    plt.scatter(features[predictions==i, 0], features[predictions==i, 1])
plt.show()
 
@Paul, thanks a lot. I will follow that and run the code now. I will let you know about output.
 
I copied your for loop that you posted, but it seems that is not quite the right thing to use, but it looks like you get the idea.
 
Is itertools a package?
 
5:51 PM
It is a module in the stdlib. Just do import itertools
 
Yeah I will make necessary changes
thanks Paul
 
itertools is a very powerful set of tools, though some (like groupby) take a little practice. But worth the time to learn.
See Doug Hellmann's Py Module of the Week entry: pymotw.com/3/itertools/index.html
 
Yeah groupby is helpful.@Paul, thanks a lot 👍🙏
import itertools

colors=['red', 'green', 'blue']

color_getter = itertools.cycle(colors)

for i in range(0, 3):

    next_color = next(color_getter)

    # do whatever is appropriate to use the new color

    plt.scatter(features[predictions==i, 0], features[predictions==i, 1], color=next_color)

plt.show()
that worked perfectly. It plotted me three clusters, each being a different color.
@Paul, thanks for the help.
I will now try using itertools on a problem that has 6 clusters.
 
6:08 PM
Why not just do for i, color in enumerate(colors): there?
 
^
itertools.cycle(colors) is extensible but I'm not sure they have a proper grasp on lopps + indices. It seems a little like running before they can walk. That's not to be disparaging, but we might be skipping over some learning here
 
I have used the enumerate function only once in my coding experience , so I agree with Rogan. But I will definitely try Aran's technique.
 
I would prefer not seeing them iterate over colors, as they should really be driving their loop from the shape of their data, which it appears is given by range(0, 3) (or just plain range(3) would suffice too), and colors is just a plotting attribute.
 
That's the specific context of the problem, but the fact they originally had 2 for loops points to a deeper misunderstanding
 
Though it probably would be good to learn enumerate before diving into itertools
 
6:17 PM
The qualification I am currently doing is self-paced. So I do not have a lecturer teaching me. I am lucky to have assistance from you guys.
I will read up on the enumerate function.
 
Alright, time to make another weekend disappear by playing Genshin Impact. See y'all in what feels like an hour, i.e. on monday
 
@Aran, thank you for the assistance. Enjoy the weekend. See you on Monday.
 
@Destroyer-byte - if you know that you will always have as many or more colors defined than in the range, you can just access the colors list using the same i index:
for i in range(0, 3):
    plt.scatter(features[predictions==i, 0], features[predictions==i, 1], color=colors[i])
 
Thank you Paul, this technique seems a bit more understandable for my level.
I am off for now. Have a good weekend everyone.
Thank you for the help.
 
6:35 PM
Same to you :)
 
6:48 PM
@PaulMcG Well how many timesteps do you intend to go out to? Near where the increment dt=0.01 will test the limits of float16 precision, float precision, double precision, etc? Perhaps you precompute a tmax value (such that (t+dt) - t != dt) and raise an FP-inexactness warning when you exceed t >= tmax. (But in general I don't see that being a real problem in general, since numerical errors in the actual integration itself will tend to be larger).
 
In the timesteps I tried since making that addition, you are right - the accumulated time t is not so much an issue, but the integration simulations work better. That being said, it still seems that something is suspect in my implementation (which for the record is actually RK4, among the various flavors of RK). Doing a simple 2D projectile trajectory, my accuracy improves when reducing dt from 0.1 to 0.01 to 0.001, but then starts to get worse!
When I've done numerical integration in the past, Euler's method or Trapezoidal method, or whatever, reducing dt has always reduced the error in the approximations when compared to an analytically computed solution.
 
Friday puzzle: two constrained partial block-placing puzzles using 12 pentominoes on 12x12 grid and 7x15 grid usig 2x5 tetrominoes. Pieces can be flipped or rotated. ... for extra credit, write a constraint-solver and show it uses an optimal heuristic...
 
An RK integrator was one of my first college computing homework assignments (freshman course Computing Fundamentals, writing FORTRAN).
 
@PaulMcG Sounds very counterintuitive, can you also measure for steps like 0.05, 0.02, 0.015, 0.012... 0.007. Could you please post that, if not on-topic for SO, the SE-network site which would get better answers: according to this suggests Computational Science.SE
Non-monotonicity of error wrt timestep size...
 
7:05 PM
Hello
 
@smci Good suggestion, will do, but it won't be for a few days.
 
What is this chatroom for?
 
@M.FurkanYOLAL Python-related topics. Please skim the rules linked in the top right.
 
I get this error, can anybody help me?
https://dpaste.com/AW2JQWSZZ
 
@M.FurkanYOLAL Re your question How can i update my PyQt5 program from GitHub?, it was missing a tag , it's not realy Python question. But you need to clarify what you expect by "I want to control version the program from github when the program opens". You mean that when you open an executable, that somehow should trigger a git pull of new source followed by a fresh build? ...
...Better to look into Continuous Integration instead.
@M.FurkanYOLAL SyntaxError: invalid syntax because you're trying to do Python literal_eval() on an HTML comment or file, under Python. (Is that really waht you intended? How do you expect Python interpreter to handle HTML comment?)
 
7:14 PM
My code is
So I didn't use XML comment in Python.
My lib use it.
And I didn't re-ask my question.
They are different questions
 
@M.FurkanYOLAL What I said. How on earth do you expect Python ast.literal_eval() to treat an HTML comment or file? It expects to get valid Python, which that ain't. What is the intent of your code?
Instead you could use html.parser package, or some other HTML parser like BeautifulSoup or lxml - please see the hundreds of existing Q&A on those. Depends what you're trying to do, and how complicated that HTML is, and how much you want to process it.
 
I use the ast.literal_eval function for dict to str that I got data from my website to use in Python but data is like this:
{'id': 1, 'name': 'M.Furkan YOLAL', 'email': 'fyolal2006@gmail.com', 'key': '12345', 'mcount': 857429, 'message': 'info'}
I dont use any XML comments or something like that.
You can try with this link:
http://myolal80.pythonanywhere.com/wp/_12345_
 
It could just be me but it feels like this code is borked in multiple ways
You're taking a response that isn't Python, parsing it, then expecting it to execute as python. Is that correct?
 
Actually my response is a dict.
And ast.literal_eval function converts str to dict
 
@M.FurkanYOLAL But your error is clearly telling you that HtmlRequest() is returning you a string with an HTML comment. So print that out first and inspect it visually, before trying to run ast.literal_eval on it. Rubber ducking 🦆; always distrust and recheck each of your assumptions...
 
7:23 PM
It would be helpful if you followed the formatting guide. I'm moving the broken code in the meantime
 
My parameters that I send to the 'HtmlRequest' function like that:
HtmlRequest('12345',True)
 
@M.FurkanYOLAL Print the output that HtmlRequest() is returning you. It apparently contains an HTML comment. (No point in arguing with us that it shouldn't be returning that... recheck your assumptions... "when a theory collides with reality, reality wins..." as one CS professor was fond of reminding us )
 
05:00 - 20:0021:00 - 23:00

« first day (3653 days earlier)      last day (1299 days later) »