#algos-and-data-structs

1 messages Β· Page 83 of 1

sharp yarrow
#

i shouldnt

#

then how to do it

shut osprey
#

because it doesn't give you the command output

#

look at the first example box on there

pseudo axle
#

i don't know whether it's the compiler which is messing things up or me
the program i've written doesn't show any output at all
i'm supposed to make a program for converting Celsius to Fahrenheit or vice versa

x = input("What unit of temperature do you want to convert,ie, 'C' or 'F' \n")
y = int(input("Enter the value of the temperature \n"))


if x=="C":
    print(y ," Celcius is " ,(y*(9/5) + 32) , " Fahrenheit")
    
    
if x=="F":
    print(y ," Fahrenheit is " ,(y - 32)*(5/9) , " Celcius")

the input for x is C and for y is 32

#

sorry if this isn't the right way to ask for help

shut osprey
#

But your program works for me

pseudo axle
#

i'm using an online compiler and it doesn't show anything for some weird reason

sharp yarrow
shut osprey
#

Look at the first example box

#

They give an example of a line where they run ls -l /dev/null, and they get the output back in the returned objects .sdout

hasty sorrel
#

if I set a variable i = 0 to keep track of what I iterate through a list, is that variable referred to as a pointer?

runic tinsel
#

of course

#

100%

hasty sorrel
#

ty

wide prism
#

i would find that to be surprising usage of that word

runic tinsel
#

exceedingly few people know this

hasty sorrel
#

I can recall reading a random disparaging comment about 'people not knowing how to use pointers' and might've read articles about them, but source amnesia makes me forget

wide prism
#

pointers are a thing in other (non-python) languages

runic tinsel
#

a pointer is not a variable you described

#

it only works in one direction, a variable you described is a pointer

wide prism
#

i can sort of see someone trying to make a point about how assignment works in python by calling python variables pointers, but i think that'd be kind of deceptive

hasty sorrel
#

hm.. so what you're both saying is that pointers in other languages are one-way increments

#

and setting a variable and incrementing it resembles them but isn't a 1:1

wide prism
#

in c and c++ a pointer holds a memory address

runic tinsel
#

no, not increments, I didn;t mean that

wide prism
#

i'm not sure what you mean by one-way increments so i'm not sure what to say to that

placid sonnet
#

if I set a variable i = 0 to keep track of what I iterate through a list, is that variable referred to as a pointer?
@hasty sorrel No it's usually called a loop variable or loop control variable.

hasty sorrel
#

thanks!

cyan gull
#

Im new to coding and want to make something that clicks on certain images if they are on screen, are there alternatives to sikuli

small kettle
#

Im new to coding and want to make something that clicks on certain images if they are on screen, are there alternatives to sikuli
@cyan gull depends of you are doing. If it's something like a web-site, maybe selenium would be a better option

cyan gull
#

For window applications in general @small kettle

small kettle
#

For window applications in general @small kettle
@cyan gull the main problem is the way you detect the things on screen. As I understand Sikuli user image recognition to find where to click. Don't think there is another free tool that does the same

#

if you only already know when and where to click, maybe PyAutoGUI might be useful. Don't know how good it is, just founded it.

fiery cosmos
#

I think this is the place. What would people recommend for memory allocation in a linux vm? default is 1024MB but I find that slow

trim flare
#

Anybody work w/ Classical Planning here?

fiery cosmos
#

What is Computer Science. I dont really have a clear understanding of what it is and what it is used for.

shut osprey
#

Computer science is the study of computation and information. Computer science deals with theory of computation, algorithms, computational problems and the design of computer systems hardware, software and applications. Computer science addresses both human-made and natural in...

fiery cosmos
#

Ooooh algorithms

unreal sphinx
#

Hey, got a couple questions!
So computers use bits to represent numbers and symbols.
Number 50 in binary would be 00110010
Letter 'A' in binary would be 01000001

  1. So how does the computer tell whether we are thinking of a number or a letter?
  2. Is UNICODE simply an extension of ASCII? So in ASCII we have 7 bits to represent symbols. But in UNICODE we have multiple bytes, therefore, much more numbers can be formed that represent a certain symbol.
    EDIT:
  3. Also how come UTF-8 only have 1,112,064 possible symbols when 2 to the power of 32(4 bytes) is 4,294,967,296
torn scarab
#

@unreal sphinx

  1. I'm not sure what you mean by thinking of a number of a letter, mind explaining that?
  2. It's not an extension per se rather a new standard for encoding text. UTF-8, UTF-16, UTF-32.. are different implementations of Unicode encoding.
  3. UTF-8 with a 4 byte limitation supports 2 ** 21 code points, or 2,097,152 characters. This is because the encoding is variable length, so if you see this table here: https://tools.ietf.org/html/rfc3629#section-3, not every bit in the 4 bytes is available for encoding.
    The 1,112,064 possible symbols you stated is the number of valid Unicode code points in UTF-8, which hints that not all UTF-8 code points are valid Unicode. The number of valid Unicode code points is 17 * (2**16), which is 2**16 code points per plane, multiplied by 17 total planes. Of those 1,114,112 code points, 2048 of them are surrogates for UTF-16 (see: https://en.wikipedia.org/wiki/UTF-16#U+D800_to_U+DFFF), which brings the number down to 1,112,064.
unreal sphinx
#

@torn scarab

  1. I mean that if we enter 65 (number) and 'A' (letter) computer converts our input to binary, in this case it would be 01000001 in both instances. How does the computer know that we meant to input one or another if it's the same in binary?
    Also if we look at the ASCII (and in UNICODE I guess the symbols would correspond to the same values, correct?) table, digit 5 is represented as 00110101 in binary, so I initially thought that a number like 65 would be represented as series (or string if you will) of two bytes 00110110 (6) and 00110101 (5). But 01000001 is also 65, and letter 'A' is also 01000001. What? How?
runic tinsel
#

it just does

#

there's no interesting answer

unreal sphinx
#

4Head

runic tinsel
#

ok, it never thinks of it as A

#

or 65

#

why do you think it ever knows it's an A

torn scarab
#

@unreal sphinx that's less about encoding and more about how keyboards work.
when you press a key, the microprocessor sends something called a scancode (https://en.wikipedia.org/wiki/Scancode) to your computer, which your operating system interprets into a keycode and subsequently the corresponding symbol, based on your keyboard layout

unreal sphinx
#

Because if we do some kind of action that involves letters (let's say concatination), it must understand that we want to combine letters A + X and not 65 + X, right? @runic tinsel

runic tinsel
#

idk

torn scarab
#

@unreal sphinx ah, if you're talking about how the computer knows it is 65 or 'A', it doesn't

unreal sphinx
#

D:

torn scarab
#

the computer just knows the series of bytes, it's up to the program to interpret it into a number

runic tinsel
#

why can't it concatenate 01000001 +X

torn scarab
#

for example, in C:

int number = 65;
char character = 'A';

both number and character will have the same binary representation, it's up to the program to track what kind of data is represented by which byte

#

here's a tiny C program:

#include <stdio.h>

void main() {
    printf("%c", 65);
}
#

this prints A, because we tell printf to interpret 65 as a character using %c

#

if we used %d instead,

printf("%d", 65);

the program will print 65

#

so TLDR: The computer does not know, it's up to the program to decide.

#

@unreal sphinx

unreal sphinx
#

So let's say we are typing something in Visual Studio Code, as we make our clicks on the keyboard, we are sending bits of information to the computer in such manner where every letter, digit we type has a binary code presented in the UNICODE table.
To return to my previous example, typing in 65 is presented as 00110110 (6) and 00110101 (5) to the computer. Then, when I try to compile something, the program sees 65 together and interprets it as a whole number and then it is transformed to 01000001 for computer to work with? @torn scarab

runic tinsel
#

you made it all up janis

#

i guess that's why you're asking because it sounds made up

unreal sphinx
#

that is the conclusion I came to from kosayoda's explenation.

runic tinsel
#

so yeah

torn scarab
#

@runic tinsel do you have anything constructive to add?

runic tinsel
#

never

torn scarab
#

then I suggest you stop sending messages until you do

runic tinsel
#

forever? OwO

unreal sphinx
#

for my sanitys sake, did I understand it correctly? @torn scarab

torn scarab
#

@unreal sphinx that sounds right-ish, you're mixing up many levels of abstraction so it's not exactly how things work

as we make our clicks on the keyboard, we are sending bits of information to the computer in such manner where every letter, digit we type has a binary code presented in the UNICODE table.
when you click on the keyboard, the keyboard sends scancodes to the computer, you're free to look it up and see the different codes

#

For a book about computers at the hardware and software level in general, I recommend Code - The Hidden Language of Computer Hardware and Software. It's not very specific, but should give you a lot of insight into how computers work.

unreal sphinx
#

ngl, I think I'm too dumb to understand it.
I guess leaving it at
"every symbol has a representation in bits which is what the computer works with and it's up to the program to interpret it the right way."
will be enough for the average Joe CS Student. @torn scarab

oblique panther
#

@unreal sphinx if you write a program in, say, C, you'll be keeping track of what you use each memory location for.

#

So even though each memory location is fundamentally just a sequence of zeroes and ones, they'll be interpreted as a char if that's what you said you wanted to use it for. Or as an int, etc.

unreal sphinx
#

@oblique panther Cheers!

#

I'm currently looking into the differences between interpreter and compiler and the explanation I have come on is that interpreter translates each line of code into machine code separately and the computer executes each one of them immediately. It takes more time to finish, however, you are able to follow along and if say one line of code returns some kind of error, you can trace back and change it.
Compiler supposedly takes the whole code, translates it all into machine code and then the execution part is very fast but if something breaks, well tough luck.
The thing is, I've done a little of C++ programming (compiler needed) in the past and once the program was executed, I still received an error and the line number where it occurred. How come?

brave oak
#

you compiled in debug mode

#

which allows you to do that by making fewer optimisations and storing relevant information

#

you can think of it as retaining a sort of mapping from the compiled code to the original source

fair summit
#

a compiler is a program that takes as input some source code of language A, and outputs source code of lang B.
an interpreter directly runs code as it reads it.
however, there is more to compilation than good old ahead of time (AOT) compilation where you list all your source code and it generates an exe, other forms do exist, first, nothing says we have to target machine code, we can target bytecode for a VM like CPython (yes python is compiled), we can also compile code while we are running it, this is called just in time compilation (JIT), we can also target some other high level language, for example, C is a common target for compilers, but so is javascript, the main benefit is that you can make use of the ecosystem of the language you are targeting.
@unreal sphinx

#

transpilation is just another term for compilation when the target language is human-readable

loud trail
#

technically cpython (the reference implementation of the python language spec) compiles python code to its own bytecode, which it interprets line-by-line

#

this is not unlike how java's JVM works, except for the fact that the JVM is a public spec and the cpython vm is an implementation detail

#

and of course other python implementations work totally differently πŸ™‚

oblique panther
#

JVM bad.

silk knoll
#

Will del immediately trigger garbage collection? Or otherwise how can I immediately free up memory from a now-unused variable. Memory doesn't seem to be immediately freed after a variable is no longer used, does the variable have to actually go out of scope before it's GC'd?

oblique panther
#

@silk knoll this is not the right channel for that question, however del will not immediately trigger garbage collection.

#

it will only decrement the reference count, which may cause it to be garbage collected thereafter

#

there's no straightforward way to free memory on demand. Is there a reason you need this?

silk knoll
#

Yes, i need to build a number of numpy arrays, each being several GB, i need to do them in batches because otherwise I will need over 100GB of RAM

#

So I need to process these arrays, save them and drop them from memory before processing the next batch

loud trail
#

usually del should work

#

maybe run it on a smaller sample and keep an eye on memory usage

#

but it wont actually delete the object unless youre sure there are 0 references to it

silk knoll
#

del is indeed working, i'm not sure how long it takes before GC actually happens, but there seems to be enough time between finishing one batch and the next starting after writing to file

loud trail
#

since it has to do with the language itself and specifically the behavior of cpython

silk knoll
#

I only mentioned it here because i remember GC being a large part of a module during my CS degree

pine basalt
#

damn i dont understand a word of this, but it sure looks interesting

covert moat
#

Is there a way I could print out my cpu temperature in python?

autumn kayak
#

a math question in a cs channel? go for it

acoustic jackal
#

Can someone help me with this math? XD

icy fulcrum
#

What are some HP Cluster options? I'm setting up a Pov-Ray render farm (2 dell servers nothing terribly big) ill be using python for building the scene files. Im not sure if an hpc is even the right option should I be looking at job scheduling instead?

gloomy bison
#

Hey guys I freakin hate Binary Search Trees questions but I need to study it, How do I get the motivation and wherewithal to push myself to learn?

shut osprey
#

The satisfaction after figuring out how they work is a pretty good reward to focus on

#

What types of questions aren't you understanding

#

narrow down what you specifically don't understand with binary search trees

shell abyss
#

My first job was to do optimization for a really computationally heavy simulator. I had to implement a binary search to speed up some of the simulations because they were taking days to complete and there was a bunch of poor, stressed out mech engineers that just wanted their simulation results. Long story short: firmly understanding algorithms and data structures allowed me to make a lot of people happy at that company. If you plan on working professionally in the future and want to earn the respect of your colleagues you should learn these skills properly.

mossy scarab
#

is there a designated text channel for machine learning (neural networks)?

fair summit
mossy scarab
#

ok tnx

fiery cosmos
#

could i ask a physics related question here?

shell abyss
#

You can always ask, if anyone will be able to help you is a different matter though

fiery cosmos
#

yes

#

on part A of my code, its supposed to use a user-input height h

#

i take that height and calculate the orbital period and re-calculate the height using the orbital period. I print the difference in them, which should be zeroβ€”or close to itβ€”but its not very consistent at it and i dont know why or what i can do to make the equation clearer to do algebra on it

#

h=(GME4Ο€2T2)β…“βˆ’RE

shell abyss
#

could be floating points messing with your difference. In computers float - float does not always produce zero

#

if the difference is very small but not quite zero I reckon it could be floating point precision. If the difference is very large then you might have some bug in your code

fiery cosmos
#

ok thanks

#

i figure its that the arithmetic is wrong because the difference is not constant

shell abyss
#

My orbital mechanics skills are very rusty though, so I am perhaps not the best one to help you with this problem. Just from hearing what you describe I think floating point errors, but idk. You could try one of the physics or mathematics discords to see if anyone there can check your math

fiery cosmos
#

fixed it πŸ˜‰

#

it was a variable error, I got confused with so many in the program that I used an incorrect one for that specific calculation

#

ty

shell abyss
#

Excellent πŸ˜„ Glad it was solved πŸ˜„

fiery cosmos
#

hi i want to print the variable as it is but i am getting an error

slender sandal
#

\\ instead of \

fiery cosmos
#

@slender sandal thanks

quasi oracle
chilly dove
#

hey guys so i am wondering where to start if i want to make a python script that looks at an excel file and prints some resaults i put in parameters

#

i was also thinking if its a good idea to hook it up to regex

drifting drum
#

Yes, there's xlsx and also openpyxl. If you're working with Excel 2010 or later, choose openpyxl, Excel 2007 - xlsx. Also, if you've got like really large files, then xlsx is usually faster than openpyxl

#

Openpyxl is usually a good all-round choice

limpid abyss
#

i want to ask that im have data mean training data for object detection and i want to use tensorflow for this puporse i m labeling picture but the problem is that all the picture (mostly is in horizantal) and im labeling them i want to ask that is there any problem after my model will train coz of horizantal pic>>>>>>>............sorry for RiP Inglish

loud trail
severe plank
#

i have done all the coding for my discord bot but its saying its offline what do i need to change

lean dome
next grail
#

whats flowcharts

bitter thorn
#

hey can someone help me write a code?

#

idk where to start

sick isle
#

I know this server is for python but does anyone hear know how to use c++

#

@severe plank I don't know I will research it and get back to u later

quasi oracle
#

I know this server is for python but does anyone hear know how to use c++
@sick isle Like you said this server is for Python. You can ask your question in an off-topic channel, but I think there should be a server for C++

sick isle
#

ok cool thanks also i have been meaning to learn python

#

any advise on wear to start

quasi oracle
#

We have a bunch resources on our website

#

!resources

halcyon plankBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

shut osprey
#

What previous programming experience do you have if any

#

this is pretty comprehensive

#

make sure to supplement it with small programs as you go along

long sleet
#

hi guys. When making a nn, how do u know how many layers/neurons will u need before training it?

quasi oracle
#

Depends on your architecture. People usually start with existing, tested, researched architectures, and tweak them

candid venture
#

Hey can someone suggest me a intermediate python online course pls! πŸ™‚

drifting drum
#

@candid venture I'm not sure about a course, but if you're a reader, Effective Python and Fluent Python are really good books

bleak oriole
#

I am a beginner in Python, can anyone suggest me a good book?

rain relic
#

!resources

halcyon plankBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

tardy echo
#

Hello

#

New to python and to this chat

opal cypress
#

Why are computer science programs so heavy in math? as far as I've heard you barely go on to use any of that math, and programming most of the time only requires basic mathematical skills

fair summit
#

CS != Programming

opal cypress
#

already answered in a different channel, no worries

marble basalt
#

Computer science is a discipline of math, like algebra or calculus

last blaze
#

Not really

#

In fact

#

Just no

loud trail
#

i think it's fair to say it's a branch of applied math

#

and there's quite a bit of interesting and novel math that has been developed in service of computer science, by computer scientists

last blaze
#

I think that's only fair if you also take the arrogant view of "physics is just applied maths"

loud trail
#

fair

half lotus
#

And chemistry is just applied physics... and biology is just applied chemistry

hexed ferry
#

what is **Kwargs exactly?

marble basalt
#

it means take any keyword arguments left over and put them in a dictionary called kwargs

#

!e

def example(**kwargs):
   print(kwargs)
example(test = 1, stuff = "this")
halcyon plankBOT
#

You are not allowed to use that command here. Please use the #bot-commands channel instead.

gaunt forge
#

You need a lot of math in algorithm development

#

and a programmer isn't necessarily good at something like algorithm development, you need both CS fundamentals and stuff like linear algebra and calculus

hasty junco
#

Coding is like being a ninja in naruto; some people use ninjutsu some people use genjutsu etc

#

Math is like ninjutsu where ui development is like genjutsu

#

if your a pen tester, game developer, ml engineer you need math. If you are developing apps with database, not much math required.

marble basalt
#

I don't think a pentester needs much math beyond like knowledge of binary

limber zephyr
#

I want to make a Roblox account verification system and change name of discord user to Roblox username. How to get started?

#

using requests?

#

Ping me when u help pls

fiery cosmos
#

can anyone solve some c/cpp question for me please
I'll send 6 questions and you got to solve any 2 question .Please,this is very important for me

last blaze
#

That's very clearly homework

#

So no

#

And even if it wasn't

#

This isn't the right channel

fiery cosmos
#

ok man i got no one 😒

mortal arch
#

facepalm

#

You have a giant squish brain between your ears. It can do amazing things. It's provided by your genes after countless years of evolution to ensure their survival in the harshest environments. You can solve those C++ questions, we believe in you!

tribal pendant
#

At least you should know how to find answers on the internet, that’s the most important skill for programmers

fiery cosmos
fallen field
#

Does anybody here has Visual Studio?

#

And help me open a .res file in that.

rough fractal
#

RES is a file extension for a compiled Win32 resource file format used by Microsoft Visual C++, a software development program. RES files may contain images, cursors, sounds and version information. ... C++ is a superset of the C language that uses an entirely different set of programming concepts.

#

so I think u should download codeBlocks at first cuz there is no official c++ app like python so install codeblocks at first in ur pc

#

and u know what codeBlocks is the official software of c++

snow spire
#

guys i need help with an image recognition bot

#

so its general premise is that it will detect a grey color and click on it and then go to a preprogrammed place on the screen

#

and this action will loop

#

my only problem is that once it is done click all the grey spots on the screen it will have to scroll down the page

#

and i dont know how to program a loop for it to click on the grey spots and once it cant find them anymore it will go down

#

any help on how to create a loop that will fix this?

shut osprey
#

!rule 5

halcyon plankBOT
#

5. Do not provide or request help on projects that may break laws, breach terms of services, be considered malicious/inappropriate or be for graded coursework/exams.

snow spire
#

this is a personal project

#

im on summer break

#

its literally a bot im using to unsubscribe from youtube channels

#

idk how to implement a loop feature of it

#

://

marble basalt
#

That is against YouTube's TOS

#

You can use their API to do that though I believe

snow spire
#

okay

#

but can someone answer how i can implement a loop

#

cause thats the question

stable pecan
snow spire
#

aight thanks

fallen field
#

so I think u should download codeBlocks at first cuz there is no official c++ app like python so install codeblocks at first in ur pc
@rough fractal Oh thanks very much. Can I open the obtain the resources in that .res files with that?

serene mango
#

Hello.
Suppose we have 3 slots with each having its own weight (l,m,n) and a three points {a,b,c} with their corresponding counts (i,j,k)
I need to find NUMBER OF triples representing the sum of counts of the points {a,b,c} in each of the 3 slots. (we will get a triple this way)
Such that there are odd number of elements in the first slot, even in second and even/odd in third slot.
We can have more than one point in each slot or 0.
For fixed a fixed triple (r,s,t) representing the number of sum of elements in each slot, such that (r) is odd , (s) is even, (t) is a even/odd
We should have r *l + s *m + t *n = x (for a fixed x)
all are non-negative integers.
Any ideas?

candid osprey
#

there has to be some other implied condition, because if im not mistaken there are an infinite number of solutions for this

#

can n m and p be only positive integers for example?

serene mango
#

@candid osprey my bad, All are non negative integers

#

I am thinking of doing it recursively for every n, and then pairs of 2 and so on.. and then to optimize it a bit, we can store the repeated products ... but it is still a very bad way I think

rough fractal
#

@fallen field yes after downloading codeblocks u can write c++ code or u can put res file and then u can run it via cmd

fallen field
#

@rough fractal Can it open all types of files. My resource file contains images, textures, models. Can I open them by this method?

#

I've tried many methods but no success. Thats why i'm asking again.

rough fractal
#

it can open all types of c++ file but why u wanna open res file

#

did u make it

#

@fallen field i have an ques for u

#

you resource file is a script of c++ right?

fallen field
#

Oh sorry, internet got hanged.

Yes! The .res resource is script of c++

#

did u make it
@rough fractal I didn't make it. It is a software's resource file. I'm on a project to modify that software's interface. I did manage to find the right file but it was a .res file. That .res file actually contains images, textures and models. I googled but there is no answer to open .res files.

#

I managed to open .res sound files by Audacity.

rough fractal
#

i know but in c++ script there is no containing img file

#

its impossible

#

u only write c++ code in a .res script but if u wanna put img then u have to use html

#

there is know option to put a img file into c++

fallen field
#

Oooo. I don't know but everyone says they are opening .res files by vs.

#

Visual studio

#

Do you have VS?

rough fractal
#

yes i am using also vs

fallen field
#

πŸ˜ƒ

#

Yes! Can you help me?

#

I'll you files and you'll try open them??

rough fractal
#

but before u put a .res file u have to download codeblocks

#

that's the official app for c++

fallen field
#

Oooo. Okay. Will do...πŸ‘ πŸ‘

rough fractal
#

okay#

quasi oracle
#

I remind you that this is a channel about computer science concepts and their relation to Python. Opening .res files with C++ is neither of those things πŸ˜…

#

If you want to talk about C++ you can try one of the off-topic channels

rough fractal
#

so

#

what does computer science mean?

#

I am a computer science student.....

#

computer science not only mean about python about various types of programming thingπŸ˜†

quasi oracle
#

Yes but this is a Python server, it's not really the place for help with C++, which is why I'm suggesting an off-topic channel.
And in case someone needs help opening a file in Python they can open a help channel #β“ο½œhow-to-get-help

rough fractal
#

ok then sorry

quasi oracle
#

all good, just letting you know

rough fractal
#

okay bro

#

btw nice to meet u I am show from Italy

fiery cosmos
#

is picking first four cards from a shuffled deck OR randomly pick four cards from a sorted deck equivalent actions?

gaunt forge
#

in the output it's equivalent, but they're not computationally equivalent

last blaze
#

Assuming the deck is a stack, then the time complexity is very different. Assuming it's just an abstract representation of a deck, then the two actions are equivalent (unless you're putting cards back in some other action)

gaunt forge
#

It's still more computationally expensive since you're generating random numbers

#

it's equivalent output, not equivalent action

#

You're also calling several different places in memory as opposed to just one

last blaze
#

if it's an abstract representation of deck - there's no order

#

so, there's no meaningful difference

#

or any difference at all

#

since i'm not talking about any underlying implementation, just the conceptual actions

gaunt forge
#

Fair enough

silk knoll
#

Can anyone recommend a optimization function that can search for a minima where there are 5000 variables?

#

SOmething like nelder-mead or powell that performs better with large numbers of variables

#

Or alternatively, would some kind of evolutionary algorithm work better?

fickle dust
#

What is your objective function? Do you have auxillary information or derivatives of it (e.g. for optimizing chemical structures you are trying to minimise the energy, but you can use the derivatives of the energy function to guide the optimization)?

gaunt forge
#

Are you searching for local minima or absolute?

#

I've got some ideas/concepts worked out, but won't bias anyone with those since I'm also interested in other takes

silk knoll
#

@fickle dust No derivatives, I'm pretty much just searching, hence using nelder-mead
@gaunt forge In an ideal world absolute, but I know for a fact that there are a load of local minimas to get stuck in

gaunt forge
#

Ah, no derivatives either, hmm

fickle dust
#

you're pretty much stuck with line searches and simplex then :(

unless you want to try simulated annealing or something like that as it can be useful for quickly traversing the function space. depends how stuck you get in wells, and how "nice" the function space is (i.e. is it smooth or very jagged)

silk knoll
#

How well do they perform with 5k variables?

#

Thats my main issue

fickle dust
#

I know there are some numerical libraries that try to generate first/second finite differences to help speed up convergence, but i don;t think that would help here

gaunt forge
#

Nelder-Mead seems pretty legit for your purposes, but I don't know how noisy your signal is or the relationships between variables

silk knoll
#

Basically, i'mm trying to concatenate the outputs of 5 neural nets, each which have 1000 possible classes, im tring to generate weight for each prediciton by each model for ensembling

gaunt forge
#

Gotcha

#

Interesting problem

silk knoll
#

I used nelder mead to weight each prediciton on a per model bases which was alright

#

Now I want to do per prediction per model

gaunt forge
#

How are you weighting speed vs accuracy?

silk knoll
#

I'm only interested in the final ensembled accuracy

gaunt forge
#

Okay

#

Is does seem like there are a few modifications or similar methods to Nelder-Mead and maybe one of them suits your purposes better. I'm not sure though, I usually have derivative/energy information to work with.

silk knoll
#

It just takes hours, I might opt to use an evolutionary approach to select values instead

gaunt forge
#

hours, eek

stuck ferry
#

Can someone explain O(n) stuff to me? over my 7+ years of coding i could never understand it

#

Ive had over 4 college professors and havent been able to learn it from either one

fair summit
#

it's a notation used to describe the growth in runtime (or memory usage if specified) as the input size grows

stuck ferry
#

I get that but how can one tell whether a program runs in O(n) time vs something like O(n^2) or something like that

fair summit
#

O describes the "upper bound", having an algorithm run in O(f(n)) means that the runtime time as n gets larger (the input size), is at worst proportional to f(n)
Ξ© describe the "lower bound", the same thing except as n gets larger, it is as best proportional to f(n)

#

there is a procedure to do asymptotic analysis, it's called the master theorem

agile sundial
#
def fib(n):
  if n == 0:
    return 1
  if n == 1:
    return 1
  
  return fib(n - 1) + fib(n - 2)

this runs in O(2^k), because for each call of fib, it calls fib two more times

stuck ferry
#

okay I can see that

fair summit
#

it is interesting to note that any algorithm that is O(n^2) is also by definition O(n!), O(2^n) etc

agile sundial
stuck ferry
#

so if i had something like this

#
def duplicate_encode(word):
    word = word.lower()
    duplicates = {}
    temp = ""
    
    #add every word to a dictionary and increases its value if there is a duplicate.
    for char in word:
        if char in duplicates:
            duplicates[char] += 1
        else:
            duplicates[char] = 1
    
    #If there is a duplicate, a parenthesis will be placed in place of the character in the right position 
    for i in word:
        if duplicates[i] > 1:
            temp += ")"
        else:
            temp += "("
        
            
    
    #your code here
    return temp```
#

how would I breakdown the runtime for this. Its a function that prints a different parenthesis based on whether the character in the word has a duplicate or not

#

so dim would print ((( and llama would print )))()

agile sundial
#

the first thing is to clarify what "n" is

#

in this case it makes sense to call n the size of word

stuck ferry
#

okay because the runtime is based on the length of the word u provide?

agile sundial
#

right

#

so first, changing a string to lowercase takes O(n) time, because strings are immutable

#

creating an empty dict is constant, and creating an empty string is constant

stuck ferry
#

okay yup that makes sense

fair summit
#

not true

agile sundial
#

err, not really?

shut osprey
#

Big O is about the bound of the functions growth

agile sundial
#

quicksort has an average theta(n log n), but its worst case is O(n^2)

shut osprey
#

e.g. it doesn't grow faster than some constant times its big O

fair summit
#

it's common to say quicksort is O(n log n) or that list.append is O(1), but these are only in the average case and amortized average case, respectively

agile sundial
#

anyway

#

the next thing in the function, is a loop that goes over every element in word

shut osprey
#

err well not O(n log n)

#

Ξ©(n log n)

#

its not big O

fair summit
#

just want to also note that Ω,Θ,O are not about best, average, worst case

stuck ferry
#

right loop through the word string

fair summit
#

they're about the type of bound we're trying to find

agile sundial
#

yeah, big omega is asymptotic lower bound, O is asymptotic upper bound, and theta is asymptotic bound

fair summit
#

the worst case for quicksort (if we assume naive pivot) is when the array is already sorted

#

that has nothing to do with the type of bound we're trying to find

#

these are based on the size of the input

#

size, not content

agile sundial
#

in and setting a new item for dictionaries is constant on average, so that for loop is O(n)

shut osprey
#

the description column in this table might be helpful

stuck ferry
#

well I guess my issue is I dont know how to tell the Big O notation of a program

#

which if why I posted an example of something I have recently done

agile sundial
#

huh

fair summit
agile sundial
#

I have a thing of practice problems if you would like

fair summit
#

it isn't applicable to every function, but should be more than good enough

agile sundial
#

I've used that like one time in total

#

yeah

#

on average

#

no

#

yeah

#

since strings are immutable, using += on one must create a new string

gaunt forge
#

I find calculating the best case runtime is kind of pointless because then bogosort is optimal

#

lower bound on best case*

#

it is interesting to note that any algorithm that is O(n^2) is also by definition O(n!), O(2^n) etc
@fair summit How so?

#

I guess it's technically true, just unhelpful

gaunt forge
#

Imprecise, rather

silk knoll
#

It's sorta the same as how x<5 also means x<25

#

Is n is an upper bound it follows that n^2 is also the upper bound

gaunt forge
#

Yeah

stuck ferry
#

honestly all this helped me understand better in the end

quasi oracle
#

Yeah but usually people will try try to present the lowest upper bound they can think of, and often Big-O is used instead of just Big-Theta

stuck ferry
#

thank you @agile sundial @fiery cosmos @gaunt forge @fair summit and @shut osprey

gaunt forge
#

You're welcome!

sudden lance
#

Is there any resources just to learn the basics/fundamentals of programming regardless of the language you learn?

agile sundial
#

isn't the term for upper bound little o, not big o?

quasi oracle
#

little o is an upper bound that's not tight

#

is essence

#

Big O means your function is bound from above by that function times some constant

#

So there's a constant c such that n^2 + nlogn < cn^2

#

Starting from some n

#

And therefore n^2 + nlogn = O(n^2)

agile sundial
#

I c

quasi oracle
#

You could think of f(n) = o(g(n)) (little o) as "f(n) is negligible compared to g(n), as n tends to infinity"

agile sundial
#

makes sense

gaunt forge
#

I've actually never heard of little o notation

oblique panther
#

little-o notation came up once in my theory of computation class

#

what I find interesting is that algorithms that are O(g(n)) are often also Theta(g(n))

#

and the latter designation is more specific

gaunt forge
#

It is pretty interesting.

inland axle
#

I don't really know where to post this, so sorry if it's not the good place. I have a Master's degree in statistics, and I'm starting a PhD in october (in AI). I'm coding in R and I was wondering if I should learn Python, as it seems that it's the most used language for AI. So I have a few questions :
Even if I'm used to code in R, should I use Python for AI ?
And if so, at which extend should I know the basics of Python language to be able to use it for AI ?

fair summit
#

it all comes down to the ecosystem, R and Python's ecosystems definitely have some overlaps in terms of available tools and libraries, but there are many places where R is lacking and Python is basically the lingua franca, especially in deep learning for example, if you're doing "traditional ML" and statistics, you'll probably do fine with R, but if you move to other related tasks like deep learning or any other kind of numerical work, python may have more tools at your disposal

#

python also has quite a bigger community online, hence why it has more libraries, but it also means it's easier to find resources, get helped, share your work with others etc

inland axle
#

I think I'll need more than "traditional ML" as you say, at one point I'd have to learn Python, so let's do it now. I already learnt the basics, but I don't really know how I should process. Should I focus on AI with Python right now, or should I focus like 1/2/3 weeks on Python code, with exercises about lists, tuples, etc ?

sonic heart
#

Broad basics (and I would definitely count lists, tuples, dicts, sets etc. in that) and best practices are a good start. Then perhaps something like numpy/scipy? Depending on which direction you are steering.

fair summit
#

you have 3 years to work on your phd, i think investing a few weeks to learning python well is gonna go a long way

sonic heart
#

I think so too. Especially if you are going to work with biiiiig datasets knowing the basics and best practices will be very valuable.

inland axle
#

Thank you @fair summit @sonic heart !

sonic heart
#

You're welcome πŸ™‚

wicked pebble
#

Hello, I'm an intermediate(ish) programmer and I've been practicing for about a year now. I recently heard about a contest held by google called "Google Kickstart" (idk why I didn't know about this, maybe because I study alone?) and was fascinated by both the high-quality questions of the contest and also the opportunity to get my foot in the door for becoming a Google engineer. However, I recently have come to realize the enormous amount of C++ users on ALL competitive programming sites/competitions, especially in the rankings of the mentioned contest. It's quite unfortunate, but I haven't seen a single user with a perfect score of 100 in the contest using Python (at least in some of the rounds)... I know the runtimes are much faster in C, C++ and Java since they talk directly to the machine, but I would like to stick to Python. I mean, I can use C++ since I've learned it before and know the fundamentals + grammar, and most of the algorithms are the same, but do I really need to switch?

flat ember
#

I didn't know about kickstart, thanks for mentioning it! Have you tried Cython?

oblique panther
#

@wicked pebble depends on whether you're scored for execution time or development time.

#

Java doesn't run as close to the bare metal as C or C++ however

lean dome
#

Java does have a JIT that produces machine code. Setting aside warmup costs to prime the JIT compiler, it can run every bit as fast as C++.

#

but, uh, yeah - it'll be hard to compete against people writing C++ code if you're writing Python code. It's much slower. Presumably you can't use pypy?

shut osprey
#

Well not quite

#

java compiles it in real time, as its being executed

#

the overhead from that is why java is pretty much always slower than C

#

that being said, making programs in java is significantly faster, so there is def a trade off

#

I would even say in most cases java/c# makes more sense

lean dome
#

it's usually a bit slower than C++, but can be as fast, particularly for a long running program when the JIT has had a chance to compile the byte code on the hot path to machine code once and is able to reuse it repeatedly.

gaunt forge
#

I would not use Python for a competitive coding competition

#

Unless there was a real world deadline to meet

#

Not just memory/time constraints

#

If you're set on using Python though, make sure you're using the correct data structures at the very least.

#

(I'm also surprised that google doesn't have different runtime/memory constraints for python competitors vs other languages)

lean dome
#

yeah, for the CPU-intensive stuff that's common on programming challenges, it wouldn't be unexpected to see the Python code be 100x slower than a C++ implementation of the same algorithm, or worse.

#

compared to a Java implementation which might be more like 2x or 3x, and in the absolute best case < 1x

gaunt forge
#

Yeah, I've ran algorithms that took 0.01 seconds in C++ and take several seconds in Python

lean dome
#

wrt. Java, it's true that there is an overhead involved in compiling the byte code to machine code at runtime, but once it has been compiled to machine code it can be reused, and it can in some cases compile to more efficient machine code than a C compiler would give, which means that in long running processes the performance benefits of the better machine code can outweigh the fixed costs involved in generating it.

gaunt forge
#

I did not know that, that's pretty cool

wicked pebble
#

@lean dome Actually, there is an option for PyPy2( just checked ). Would that be a reasonable option? Are the speeds of it even comparable to the speed of C++?

#

@gaunt forge Yes, I was also surprised that they had an universal time/memory limit. Maybe that's why I saw so many participants in the top 100-ish rank all use C++ (because the time spent to write the code is important too). Also, if I were to stick to the language, do you think PyPy is a solution? I really don't know...

fair summit
#

Are the speeds of it even comparable to the speed of C++?
realistically, no

#

it's much better than cpython, but nowhere near as fast as C++ in a vast majority of cases

wicked pebble
#

Oh... well guess I'll have to take the contest in November(there's one every month) after practicing C++...

#

Maybe I'll regret that tho, cause I have to specify which data structure I'm using EVERY SINGLE TIME... like, in Python you can use lists, sets, and dictionaries as everything...

lean dome
#

and, pypy is in fact slower than CPython when it comes to C extensions. People writing modules for "normal" CPython will often ship a compiled extension module when they want to speed things up in a way that plain Python code can't, and - while PyPy tries to make those work - it does so through a compatibility layer that has significant overhead. The end result is that "vanilla" Python code runs much faster in PyPy, but modules designed for speed may run much slower.

#

but, that said - if I had to use Python for a competitive coding thing, I'd reach for pypy before CPython - I'd guess that it would be better.

fiery orchid
#

Hey, massive newbie here. Taking a summer math course and need to do some plotting of equations. Need to plot this
k(x) = (x^3-7x+2)/(cos(x)-1)
function on a -5,5 interwall. Nothing major. But when I try to do so I get this. Not sure what or why is making it look this way.
f = (x^3.0-7.0*x+2.0)
v = (cos(x)-1.0)
plot(f/v,-5,5).
Cut it up in two parts so its easier to see for me. Any help would be great.

#

I thought it might have been cause of floating numbers. But that wasnt it. I tried to split it up a bit more but no luck there either.

pliant crane
#

need some help with speech_recognition library

shell abyss
#

@fiery orchid I am just guessing here but it might be so that the reason why your graph is all messed up is that your function k=f/v is not defined for x=0. It would asymptotically approach infinity when x gets closer to 0. What tool are you using to plot?

fiery orchid
#

Im using SageMath, which is required by the course. But its built on python.

#

YouΒ΄re probably right. I didnt think about that its not defined for 0.

lean dome
#

The programmer can assign values to board states based on what they think "winning" looks like - in pretty much any game you can tell if you're winning or losing while playing it.

#

At least, in any perfect information game

gaunt forge
#

You can still tell your odds

#

Take poker for instance

#

Err, hold em'

shell abyss
#

@fiery orchid dunno why it would shift the data downwards though. You should get a positive asymptote which would cause the plot to move upwards

silent girder
#

Can anyone recommend a good book for intermediate programming and beginners computer science

sonic heart
#

If I have 2 list (A and B) that i want to intersect.
Both are sorted.
len(A) < len(B).
k=len(A), n = len(B)
Then should a binary search of the Elements of A in B have a best case time complexity of O(k) - algorithmically speaking. Right?

quasi oracle
#

A binary search in B would take logn. So k operations would be klogn

sonic heart
#

E.g. if A[0] = B[n/2], A[1] = B[1 - n/4]

#

then the binary search would just hit the right value each time and practically be O(1)

#

Only speaking best case

#

Sure it would be O(k*log(n)) in general

#

Due to both lists sorted i know that A[1] > A[0] so i don't have to check the left half of B again

#

Because if A[0] = B[n/2] I know that A[1] must be to the right of B[n/2]

#

better: right of index n/2

quasi oracle
#

Maybe, assuming you retain information between searches. But I'm not sure how the best case helps you

sonic heart
#

It's just a theoretical thing... no that I would expect that in reality

#

So I don't need a full binary search for each k. Sure the worst case would be that you need it. But my lecture says the best case would be O(k+log(n)) and the worst case O(k*log(n))... but I think that the best case would be O(k)

quasi oracle
#

I haven't seen the algorithm in detail, so I can't tell

sonic heart
#

Yeah.... it's not like that we have an algorithm in code for that. It is algorithm theory lecture... not really much code in that one πŸ˜„

#

Thanks πŸ™‚

sonic heart
#

I threw quickly something wacky together:

def bin_search_element(a, B):
    if B[len(B)//2] == a:
        return len(B)//2
    if B[len(B)//2] < a:
        return len(B) // 2 + bin_search_element(a, B[len(B)//2:])
    elif B[len(B)//2] > a:
        return bin_search_element(a, B[:len(B)//2])

def bin_search(A, B):
    results = []
    last_hit = 0
    for a in A:
        last_hit = last_hit + bin_search_element(a, B[last_hit:])
        results.append(last_hit)
    return results

print(bin_search([50, 75], [x for x in range(100)]))
#

And i think that supports the case for best case O(k) where k = len(A)

toxic sundial
#

Trying to pick up programming..having issues understanding how to apply object orientated programming, can someone give me some pointers?

hasty junco
#

yeah do you know the term abstraction?

toxic sundial
#

yea, i think i understnad the solid and dry principles but i am havivng trouble applying it

hasty junco
#

Theres no way you can learn solid without many applications of it..

#

there are so many aspects of it.

#

To apply OOP i recommend thinking of 5 examples right now of things with data and behaviors

#

for example: a car

Data:
cars have 4 wheels -> static variable
my car is red -> non-static variable

Behaviors:
cars are becoming more gas efficient -> static method
my car is accelerating -> accelerating non-static method

#

essentially classes are blueprints for that thing and create objects/instances of that thing

#

how would you apply it? maybe you make a drag racing game

#

maybe you use the object for automating driving

#

abstract concepts have many applications

toxic sundial
#

so for car, whats the step after creating the car object? What kind of object am i suppose to create to interact with car?

hasty junco
#

you create the car class to make one or more car objects

#

thus not having to repeat yourself in writing variables and functions

#

you can make a street object

#

the street object can be black and cause friction

#

^ this may require some math.

toxic sundial
#

would there be a driver object to drive the car?

hasty junco
#

there can..

#

you can pass an object into the method of another object

#

or pass both objects into another function

#

player1.drive(ferrari)

#

this may set ferrari to the player1 variable: current_car

pliant tundra
#

So I am currently stuck on an assignment for python flask web development. I need to create a form in order to change the password of the user that is logged in.
Using an in memory data base with preloaded usernames and passwords. Is there a way to verify the user that is logged in and access their password and change it to the new entered password?
All of this is very new to me and I am having a hard time finding documentation for changing password.

marble basalt
#

How are you storing them?

pliant tundra
#

users = []
users.append(User(id=1, username='user1', password='test'))
users.append(User(id=2, username='user2', password='test'))

marble basalt
#

Is User from flask??

#

I believe you can just directly change the attribute

#

users[0].password = "new_pass"

shut osprey
#

what

vapid dirge
#

i would like to ask smething about neural networks, is this the correct place to ask?

oblique panther
vapid dirge
#

ok thanks

fiery cosmos
#

hey everyone I am using this script to get an image from a few links. but some links doesn't have an image on there I think I need to do a try and Exception line to make it still work if there is no image but what I want it to do is just skip this function if there is no image to get.

#
        uri = "XXXXXX".format(self.ES_ENDPOINT[envFlag], xmlId)
        headers = {"Content-Type": "application/json", "charset":"UTF-8"}
        self.logger.info("Fetching asset image for ID: {}".format(xmlId))
        response = requests.get(uri, headers = headers, stream = True)
        imgStr = StringIO(response.content)
        im = Image.open(imgStr)
        # try:
        #     im = Image.open(imgStr)
        #         # except Exception as e:
        #         #     im
        return Asset(str = imgStr, width = im.size[0], height = im.size[1])```
#

I get this error when it has no image ParseXML:cannot identify image file <cStringIO.StringI object at 0x1111fecf0>

fiery cosmos
#

package com.codewithneal;

public class Main {

public static void main(String[] args) {
System.out.println("Hello World");
}

}

oblique panther
#

@fiery cosmos that looks like Java. This server is for Python, and this channel is specifically for computer science as it relates to Python. Do you need help finding the right place for your discussion?

fiery cosmos
#

@oblique panther yes plz

oblique panther
fiery cosmos
#

thx

marble basalt
#

What do you mean

quasi oracle
#

Maybe you could calculate the worth of every member of your team depending on the enemy's team

finite kraken
#

im making an ai to play pokemon competitively
assume 3 fire vs fire/water/grass
in this situation losing the water type poke should have a much higher punishment than the grass one, but i cant just set "water = -50, grass = -10" because against 3 water types losing the grass type should have a larger punishment
@fiery cosmos you could make a lookup table for type effectiveness

#

effectiveness in the games relates to offensive and defensive as well

#

so maybe a combined score

#

yeah, i guess it just depends on what you are actually creating, how you want to handle things

quasi oracle
#

Try to think how you consider worth as a human player, and try to turn that into an algorithm. You could for example also consider what kind of moves each pokemon has

finite kraken
#

for how large this is, drawing it up on paper first might help A LOT

#

yeah if you kept the separate you could make a heuristic about chosing based on both stats

#

err both scores

quasi oracle
#

Well different chess pieces also play different roles. And their value can also vary in practice depending on their position

finite kraken
#

minimax is effective, but it also depends on how far you can look ahead

#

for tictac toe it can know the best move at every board position

#

but in chess it can only go a few levels deep (max)

fair summit
#

I don't think minimax can yield any result against decent players given the search space

quasi oracle
#

Not sure what you mean by hasty. You can evaluate the gain any way you want

fair summit
#

pokemon is much more complex than just "fire beats grass"

finite kraken
#

yup, if levels are too different even a type effective attacking player can be killed first

#

i think having a database with type effectiveness would be a good start

#

i have no idea how you are connecting an AI to which of the 10 pokemon games that are out there

#

you may just want to start small

fair summit
#

you can't really do that without breaking their TOS

finite kraken
#

ie get it to play

fair summit
#

i don't think any public simulator out there allows bots as well

finite kraken
#

then add it look ups for type effectiveness, get that to work

fair summit
#

tho you can run your own instance of pokemon showdown i guess

finite kraken
#

and then try to optimize from there

#

agent systems use a variety of algorithms and get scored

fair summit
#

but really, type effectiveness only goes so far, a pokemon weak to fire may have a rock move that will smash incoming fire types, type coverage is a really important aspect of the game

finite kraken
#

so implementing one wont hurt you

fair summit
#

not playing bots, no

#

uh actually you're right, there's nothing against bots, at least for now

quasi oracle
#

theres plenty bots on smogon and ToS doesnt imply its illegal
@fiery cosmos sure, but in that case we won't help with that here πŸ™‚

fair summit
#

that is, until one of them gets reqs and they get compulsorily banned for affecting the metagame in a meaningful way

#

not that it will happen anytime soon tho

frail valve
#

question for the room -- how to define computer science

#

i have reasons for asking....

shut osprey
#

Computer science is the study of computation and information.[1][2] Computer science deals with theory of computation, algorithms, computational problems and the design of computer systems hardware, software and applications.[3][4] Computer science addresses both human-made and natural information processes, such as communication, control, perception, learning and intelligence especially in human-made computing systems and machines.[5][6][7] According to Peter Denning, the fundamental question underlying computer science is, What can be automated?

#

Computer science is the study of computation and information. Computer science deals with theory of computation, algorithms, computational problems and the design of computer systems hardware, software and applications. Computer science addresses both human-made and natural in...

junior epoch
#

Hello guys I'm new to python as well as Mac and have a question. I just bought a mac a few days ago and it shipped it python 2.7. I am looking to upgrade it to the latest version but I have to clue how to do this. Please help..

round zinc
#

Just download the latest version.

#

All Macbooks come with Python2

whole cave
#

just download from the website and then change your paths

#

use Terminal to do this

#

Anyone have any experience with tkinter

#

?>

keen hearth
#

@junior epoch First, download the Homebrew package manager for mac (details here: https://brew.sh), then install Python3 by typing brew install python3 into the terminal.

#

Do you have any experience using the UNIX terminal?

shut osprey
#

also

#

!ask

halcyon plankBOT
#

Asking good questions will yield a much higher chance of a quick response:

β€’ Don't ask to ask your question, just go ahead and tell us your problem.
β€’ Don't ask if anyone is knowledgeable in some area, filtering serves no purpose.
β€’ Try to solve the problem on your own first, we're not going to write code for you.
β€’ Show us the code you've tried and any errors or unexpected results it's giving.
β€’ Be patient while we're helping you.

You can find a much more detailed explanation on our website.

fallow drift
#

Hi Guys, can someone suggest me good resources to get better and Objected Oriented Programming

oblique panther
#

@fallow drift this isn't necessarily the channel to discuss that, however I'm not sure that learning OOP specifically is the way to go

#

there are resources on the website for this server

#

!resources

halcyon plankBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

fallow drift
#

@oblique panther sorry this is my first time on this server

oblique panther
#

That's alright. I'll ping you on another channel.

fallow drift
#

Ok thanks

fiery cosmos
#

Any canadian uni students here?

oblique panther
#

@fiery cosmos why do you ask?

fiery cosmos
#

Just would like to know some input from those who are studying cs or software engineering in Canada

#

Ex: If they like it, if it's worth it or not

oblique panther
fiery cosmos
#

ight thanks

edgy bolt
#

Hey pythoners how you doing?
I recently got into WeThinkCode and we started with python, what are the best resources to begin with?

runic tinsel
#

wow, python from the start?

#

like the django thing?

bleak oriole
#

I would suggest you to start learning python from a book

#

It is one of the most versatile and reliable sources

#

Follow up these books:

  1. Python Programming 3rd Edition by John Zelle
  2. Python Crash Course 2nd Edition by Eric Matthes
#

Have a happy time learning!

wicked horizon
#

Does this look correct? Had to prove that the original expression is a tautology using logical equivalence rules

edgy bolt
#

@bleak oriole that you so much!!! pystrong

summer reef
#

What you derived is exact, however you showed that
not (not P and Q) => (not Q or P)
and you were being asked the opposite. Just follow the same steps starting from the left side, not the right one, and it will be correct!

#

(saying both sides are equivalent here works, but only because each step is reversible; you could just write that in addition to what you concluded, it would pass all right as well)

junior epoch
#

@keen hearth I have no experience using a terminal its my first time

#

Thanks for the help

vestal ether
#

does anyone know how to use tkinter?

shut osprey
#

!ask

halcyon plankBOT
#

Asking good questions will yield a much higher chance of a quick response:

β€’ Don't ask to ask your question, just go ahead and tell us your problem.
β€’ Don't ask if anyone is knowledgeable in some area, filtering serves no purpose.
β€’ Try to solve the problem on your own first, we're not going to write code for you.
β€’ Show us the code you've tried and any errors or unexpected results it's giving.
β€’ Be patient while we're helping you.

You can find a much more detailed explanation on our website.

shut osprey
#

@vestal ether

vestal ether
#

ok thanks

shut osprey
#

also this is the incorrect channel

oblique panther
#

@vestal ether #user-interfaces is the other place where you can talk about tkinter.

vestal ether
#

Oh ok thanks i’m new so that’s why

gritty anvil
#

`def MergeSort(list):
if len(list)>1:
mid = len(list)//2
left = list[:mid]
right = list[mid:]

    MergeSort(left)
    MergeSort(right)

  **  a = 0
    b = 0
    c = 0
    while a < len(left) and b < len(right):
        if left[a] < right[b]:
            list[c]=left[a]
            a = a + 1
        else:
            list[c]=right[b]
            b = b + 1
        c = c + 1
    while a < len(left):
        list[c]=left[a]
        a = a + 1
        c = c + 1

    while b < len(right):
        list[c]=right[b]
        b = b + 1
        c = c + 1
return list**

list = [2,4,5,1,6,7,8,9]
MergeSort(list)
print(list)` , I have got this merge sort algorithm from a GitHub page and trying to understand it. I understand it at first divides the whole list into middle and then sort it again until there is just one element. Then it tries to merge to get the full sorted list. But I have trouble here understanding the pieces of code that I marked with double asterisk here. If anyone can explain it in simple explanation, that will be very helpful. I know the basics of how merge sort works.

quasi oracle
#

@gritty anvil The part you marked is the part that is merging the two sorted halves.
Focus on the first while loop:

while a < len(left) and b < len(right):
    if left[a] < right[b]:
        list[c]=left[a]
        a = a + 1
    else:
        list[c]=right[b]
        b = b + 1
        c = c + 1
    c = c + 1

The idea is that since the two lists are sorted, you can only go forward when traversing them while you're trying to join them together.
a is the index where you're currently at on the left list. b is where you're currently at on the right list.
You will increment a until left[a] is greater than right[b] (or equal to it), at which point you will add right[b] to the merged list and increment b

gritty anvil
#

Thanks @quasi oracle . That is very helpful.

quasi oracle
#

The idea is that since the two lists are sorted, you can only go forward
That is in fact the key to merge sort's efficiency. Since you can merge the two lists into a sorted list while looking at each element only once, you can create the merged sorted list in linear time.

#

The running time for a list of n elements is therefore:
T(n) = 2T(n / 2) + O(n)

gritty anvil
#

Yes. Got it. Recursive running time.

tidal turtle
#

hey i am a noob to AI.
can somebody help me out with figuring what useful functions sklearn has?

fair summit
#

that's quite the broad question, have you checked their website ?

tidal turtle
#

@fair summit thanks!

hollow pecan
pallid violet
#

Hi all, does anyone know how to go about testing the accuracy of machine learning models and image recognition software? For example, I want to test the accuracy of some OpenCV functions. How can I do that?

silk shoal
#

@pallid violet you have to use that function on your data set, and create a test set from which you wilol train your model and then create validation set, and use trained fucntion on the validation set and see what's the accuracy

pallid violet
#

@silk shoal What if it is not machine learning but just image recognition with OpenCV? I am extracting info from a set of documents, like signatures, faces from a driving licence for example. Does the same approach apply?

#

Just realised I'm asking in computer-science and not data science, sorry

fierce oracle
#

Hei Guys, Have any advice for learning python?

#

what is better phython version for newbie? 2 or 3?

harsh sapphire
#

@fierce oracle Start with the latest python (python 3). I would recommend you check out Corey Schafer on youtube. He has great videos on python tutorials. Here's a link to his channel: https://www.youtube.com/user/schafer5

#

His "python tutorial for beginners" was how I got started with python. I would follow up on the questions I had by going through Geeksforgeeks.

marble basalt
#

@fierce oracle python 2 is EOL, it's not supported anymor

#

Some legacy programs might use it still, but you should use python 3 for all new code

#

What previous coding experience do you have if any

#

Well, I started here and everyone said I shouldn't bother with it because it has an old Python version, but for someone who's not just new to Python, but new to programming in general, use https://codecademy.com/.
It's very interactive, and even though you can't really do anything with what you learn, it will familiarize you with the fundamentals.
It's free. There are some other resources that you can use afterwards, but I would suggest starting here.
http://python.swaroopch.com/ (for complete beginners to programming)
https://learnxinyminutes.com/docs/python3/ (for people who know programming already)
https://docs.python.org/3.5/tutorial/ (for the in-between group, i.e. knows some programming but not a lot)
see also: http://www.codeabbey.com/ (exercises for beginners)
http://www.learnpython.org/ (somewhat interactive tutorial)
Also, this guy's video tutorials are excellent.
https://www.youtube.com/playlist?list=PL-osiE80TeTskrapNbzXhwoFUiLCjGgY7
https://www.youtube.com/playlist?list=PL-osiE80TeTt2d9bfVyTiXJA-UTHn6WwU
https://www.youtube.com/playlist?list=PL-osiE80TeTsqhIuOqKhwlXsIBIdSeYtc

bronze gust
#

I wnt to make one chatbot

#

Which can learn on its own

#

How can I start

#

Plz someone guide me😊

marble basalt
#

Wdym chatbot

bronze gust
#

Ping when someone answer

#

Chatbot means a program in computer which is capable of talking like humans

marble basalt
#

Use the cleverbot api

#

Costs money tho I think

bronze gust
#

Tensorflow?

marble basalt
#

It won't work very well at all

#

And you need quite a bit of prior knowledge to use that well

#

Linear algebra

bronze gust
#

Weak in that

#

😐

#

How can I get started

marble basalt
#

Just use the cleverbot api, natural language processing is a hard problem

maiden cedar
#

hi there
i've been looking for quite a while for a good way to calculate the trajectory of a projectile in 3d space: all the articles i find are for 2d space, and i've had a tough time trying to adapt 2d algorithims to 3d space

i have the starting velocity, the time i want to get a snapshot at, and the starting angle for all dimensions: what's the best way to implement this code into python?

sorry if any of this isn't on topic, this is my first time dabbling with physics in code
please @ me when you do respond or need more details
thanks in advance!

chrome thistle
#

with the starting velocity and the angle, you could calculate the velocities along x, y, z directions. Then only the velocity along z changes over time, (just like how in 2d, only v_y changes). @maiden cedar

#

the equations are no different in 3d than in 2d

candid osprey
#

Absolutely, instead of worrying about calculating something in 3d,this is as simple as calculating 3 independent 1d paths

#

Since orthogonal motions don't affect each other, just calculate x, y and z one by one

#

Reconcile the final values

gusty grove
#

also known as the "Superposition principle".

#

i think

zenith pagoda
#

hi, can someone help me to understand the differences between concurrently, asynchronous, parallelism, coroutine, and multi-threading in python?

gusty grove
#

concurrently is when two or more things run in the same time frame, not necessarily at the same exact time

#

asynchronous doesnt run at the same time, but instead passes computational power around. so while one function is loading a file or waiting for userinput another function is allowed to run

#

parallelism is when they are actually calculated at the same time. so both async and parallelism are forms of concurrency

#

coroutines are part of async

#

multi-threading is a way to achieve parallelism, the cpu executes different code on two processors at the same time

#

the python threading lib cant actually do multithreading, because of the Global Interpreter Lock, so it still only runs on one thread

elfin sundial
#

hey guys, I'm trying to learn Linux, not just the distro,kernel or os but i want to learn how it works and how it can be developed for. so i thought the best way to learn would be to use Linux. ik about ubuntu but i wanted to know if there was a os which had a more original Linux kernel/core that i can learn to develop for. thanks

true badge
#

@elfin sundial Linux is just a kernel, developing for a kernel isn't a great idea

elfin sundial
#

not kernel

true badge
#

people usually develop for an OS, it has an ecosystem of libraries that can be used on it

elfin sundial
#

software dev for linux

true badge
#

and you want something that can run on many distros ?

elfin sundial
#

yeah man

#

should i stick to ubunutu or should i try arch

true badge
#

ubuntu is actually based on Debian, so developing for Debian is basically developping for ubuntu

#

there's this video on how "cross-distro" package managers work

#

that allow you to build for different distros at once

elfin sundial
#

the thing is that ive actually never developed for linux os

true badge
#

same, I've only made small bash scripts to automate common dev tasks that I do

elfin sundial
#

bro i wanna learn python automation man

#

i dont know how it works

#

should i just google or do you have a good video

true badge
#

I just googled "python automation" and this book came up

#

also, I don't think it's that complicated on linux, assuming you have a good grasp of python

elfin sundial
#

right thanks mate

true badge
#

you're welcome

marble basalt
#

Linux is significantly easier to develop om

tidal ingot
#

Hello is this the channel where I can ask questions about coding?

oblique panther
tidal ingot
#

Yeah I did but I am not sure if I should ask problems related to programming or not here

oblique panther
#

@tidal ingot you can ask questions in this channel that are related to algorithms, data structures, and anything else that is specifically computer science.

tidal ingot
#

oh okay thanks

gaunt forge
#

Do you folks ever find yourself implementing an algorithm where you have no idea how it works?

#

Like, you know how to code it but don't understand what it's doing conceptually?

#

I know the effect, I know how to code it, but I don't know why it has the effect that it does

half lotus
#

Yes I had that just the other day but I figured it out after I finished

gaunt forge
#

Haha, nice

half lotus
#

I derived it from a pattern I observed but I didn't know why that pattern was occurring nor why it was the solution.

gaunt forge
#

But you managed to figure it out after you were finished implementing it?

half lotus
#

Yes

mint jewel
#

I just did it with the torus equation in ot1.

gaunt forge
#

I

#

I'm just not used to implementing something I don't understand conceptually. I can't look it up either, it's proprietary af

#

The dude who gave it to me is a genius, I just... usually I could offer my expertise to improve certain algorithms or discuss implementations but here I'm over my head

quasi oracle
#

Talk to him and figure out what you need to read to understand it

lean ice
#

So what exactly is currying, I'm having a bit of trouble understanding it

oblique panther
#

Do you folks ever find yourself implementing an algorithm where you have no idea how it works?
@gaunt forge
Last semester I took linear algebra and we had to write a paper about an application of LA for 20% of our course grade, so I implemented word2vec and described each step of the algorithm

#

but I mostly just copied a poorly written implementation I found online and rewrote it the way I would have written it, and even then I still didn't know how it worked

#

but I passed the class so who cares?

gaunt forge
#

Haha

fair summit
#

the process of taking a function that takes N argument, and convert it into a function that takes one argument, and return a function that takes one argument and return a function that takes one argument ... until you reach N @lean ice

#

it's extremely tedious to do in languages that don't do it automatically for you

gaunt forge
#

sounds terrible

fair summit
#

but basically instead of doing foo(1, 2, 3, 4) you'd do foo(1)(2)(3)(4)

#

such languages also generally have different syntax for function application

gaunt forge
#

What's the reason for doing that?

fair summit
#

it makes functions highly composable

#

you have partial application for free

lean ice
#

Im trying to have a decorator with multiple arguments

fair summit
#
let add x y = x + y
let add2 = add 2```
#

add2 here is a function that takes one argument, and returns that argument, + 2

gaunt forge
#

Right

fair summit
#

generally speaking, don't bother with currying at all in mainstream languages

#

none of them actually support them in a sane way

lean ice
#

See that’s the issue Im running into because I’d rather not

#

But I can’t use the decorator without either doing that, or changing the class around so that it’s less of a decorator and more of just a plain class

fair summit
#

can you come up with a toy example that demonstrates your problem ?

lean ice
#

Well I’m using it to check my inputs for certain things: commands present, type, any extra commands the user wants to implement, etc py @check(inp, typ, extra)

fair summit
#

and you'd want it to support @check(inp) or something ?

lean ice
#

Well more or less I want it to support all three

#

Hence the currying

#

Like it currently "works" but I had to do some funky stuff with the class

misty pewter
#

hello

#

any helpers online here atm?

lean dome
#

yes.

misty pewter
#

oh hello

#

Is there a simple way to take a given int, for example 123456789

#

and have it print as 123,456,789

#

I'm guessing there's a module for it?

#

maybe this is data science

mint jewel
#

!e print(format(123456798, ','))

halcyon plankBOT
#

@mint jewel :white_check_mark: Your eval job has completed with return code 0.

123,456,798
mint jewel
#

@misty pewter ^ the , format specifier does that for integers

misty pewter
#

thank you

#

hmm

#

@mint jewel

#

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ValueError: Cannot specify ',' with 's'.

mint jewel
#

you have a string, not an int

misty pewter
#

i thought that may be what it meant

#

in the database it pulls the number from, it's int32 though

#

oh, it goes through being in a dictionary when it gets initially pulled out of the database

#

i guess thats it

#

sorted. thanks lamatiol

#

converted from string to int, ran format and then converted from list to string again

#

probably a bit inelegant. but it does the job.

midnight berry
#

Hi guys, would anyone know why the output from np.polyfit is different from my own manual calculation through python?

zenith pasture
#
x = 0.1

x = x*15
x = x - 1.4
print(x)


for i in range(100):
    x = x*15
    x = x - 1.4
print(x)

Results in:

>>> 0.10000000000000009
>>> 3.868916401871249e+101

What exactly causes this behaviour. Is it to do with how the numbers are represented by computers?

#

I understand that in the for loop there could be an error that is getting multiplied each time, hence why it is so big?

agile sundial
#

yeah pretty much

zenith pasture
#

Is it all numbers or just some specific?

agile sundial
#

floats

zenith pasture
#

I just tested in other langs and same behaviour

agile sundial
#

floats are weird

zenith pasture
#

So how to be precise then when you need such calculation?

agile sundial
#

add a little wiggle room with > and < instead of ==

mint jewel
#

try doing

x = 0.1

x = x*15
x = x - 1.4
print(x)


for i in range(100):
    x = x*15
    x = x - 1.4
    print(x)
``` essentially, the error after the subtraction gets 15 times bigger every iteration
#

what you can do to get exact results is use fractions.Fraction

agile sundial
#

if you try the same thing with ints, there isn't any error

#

oh, probably use Fraction

zenith pasture
#

Btw by default does python use single or double precision?

mint jewel
#

floats are doubles internally I am pretty sure

zenith pasture
#

Is the problem here same as to when you write 1/3 in base 10? You can shorten the output to for example, 0.333 but its not precise, i.e. the error still exists?

mint jewel
#

yes

#

there is no way to exactly represent every rational as k*2^y in finite space

zenith pasture
#

Interesting, isnt this a pain for some systems out there. I would imagine for things like autonomous vehicles or things like rockets/missiles/sattelites where precision is essential.

mint jewel
#

for those things, sensor error is generally bigger than floating point error. It is sometimes a concern though

lean dome
#

When it is a concern, fixed point is used instead of floating point.

fossil zephyr
#

could well trained neural networks fill out a captcha? i wouldnt see a problem in that, but why are they still being used then?

mint jewel
#

the point of modern captchas is to train such networks, so if you can make one, you probably can bypass it.

fossil zephyr
#

which networks are trained? the ones from google and other tech-gaints? and i guess they arent accesible to everyone lol

lean dome
#

right - the captchas that get presented to humans - things like "find all the traffic lights" - are being used as to collect training data from humans for training Google's neural nets.

fossil zephyr
#

and we can only use their networks if we use their services like detecting letters on a sign etc

lean dome
#

but also, more factors go into a captcha than just whether or not you get the question right. How long it takes you, how you move the mouse while working on it, how many others you've previously solved, how long has it been since you last solved a captcha, etc are all used as inputs to the are-you-a-robot algorithm.

mint jewel
#

ye, the data from captchas is what google gains from providing free captcha.

fiery cosmos
#

dose eny one no to code in roblox if do then dm me

quasi oracle
#

@sinful sapphire any reason you posted those tests here?

sinful sapphire
#

@quasi oracle no srry, I just didn't know where to test them

quasi oracle
#

Could probably fit in #bot-commands

sinful sapphire
#

I'm learning a little more about discord

#

thanksπŸ‘

gaunt forge
#

floats are double precision

#

Fractions and Decimal are both useful

#

Or just be aware you're not going to get a precise comparison when you compare to real values

zenith pagoda
#

what does it mean if I/O bound software?

void linden
#

I/O bound software means its performance is mainly bottlenecked on waiting on external resources (disk, network, etc.)

zenith pagoda
#

@void linden is this related to CPU also? or it is different?

void linden
#

Well, obviously the program needs to use the CPU to processing things coming off of the network. When they say something is bound though it really means what is the limiting factor in terms of performance / scalability.

#

so CPU bound would mean that the program is limited by how much it can process given the hardware it has available.

#

Examples may help ... Think about the difference between a video processing service (add effects, encode in different formats, etc.) and a video streaming service. The first is CPU bound. It is limited by how fast it can do the work it needs to do. The latter is I/O bound. It is going to be limited by the network and disk.

zenith pagoda
#

@void linden ok thank you

fiery cosmos
#

are ruby or c# useful languages to learn?

agile sundial
#

if you want to use the things that mainly use those languages, then yes

zenith pagoda
#

when to use concurrent.futures module and when to use asyncio module?

native zenith
#

Does anyone know visual processing?

fiery cosmos
#

@native zenith Don't ask to ask, just ask.

bronze sail
#
{'worktime': set(), 'criminal': {'worktime'}, 'member': {'criminal', 'worktime'}, 'unhappy': {'member'}}

Hey, imagine having such relations, node name, and parents, how can I check if this tree would be sequencial and there is no looping?

unique ginkgo
#

hello!
Can someone help me with something πŸ™‚
I'm new to python and programing in general

#

I need help on doing a type of score

#

I am doing a trivia with questions, so when you get a question right you get a score or a point or if you get a question wrong you get minus points

loud trail
#

@unique ginkgo are you asking about how to write the code, or what kind of algorithm to use? if you just need programming help, refer to #β“ο½œhow-to-get-help

unique ginkgo
#

Mainly what kind of algorithm to use

agile sundial
#

sounds like you described the algorithm perfectly

#

if right --> add points

#

if wrong --> subtract points

unique ginkgo
#

Yes. I mean what code I need to use to get that.

agile sundial
#

that's for you to figure out

#

you need to be able to check if an answer is correct or not, at least

dusty cipher
#

Hello, is it okay the 4gb ram laptop specs for programming ?☹

agile sundial
#

shouldn't be an issue

#

unless you're doing ram intensive things while programming

loud trail
#

pycharm takes a lot of ram

#

and so do 100 browser tabs full of documentation pages πŸ˜›

#

@unique ginkgo i recommend opening a help channel, including what code you already wrote and explaining where you are having difficulty

#

also you should clarify if this is a homework/school assignment

bronze sail
#

what lib I could use to draw graph and nodes?

#

its finds me just matplotlib

mint jewel
#

plotly, seaborn are more options

stable pecan
#

shameless

bronze sail
#

@mint jewel have you used networkx ?

mint jewel
#

I have

bronze sail
#

with matplotlib or pyplot? is pyplot giving some advantage?

mint jewel
#

I used matplotlib, it is pretty convenient for this

bronze sail
stable pecan
#

graph-tool makes beautiful layouts too

bronze sail
#

that pic was made withpyplot πŸ˜„

#

and its kinda cool

#

but plotting is .. weird a litle

agile sundial
#

have you solved the problem youshisu?

bronze sail
#

not implemented but yeah, my solution was very similar to that dfs

agile sundial
#

what's your solution?

bronze sail
#

check all unvisited childs, I don't need backtracking

#

mmm the difference is that, I have always 1 root

#

in other cases I think I should use dfs

agile sundial
#

huh

bronze sail
#

I just follow arrows

#

if I visited node, -> error

agile sundial
#

well if you've visited the node already, then you're done, you found a cycle

bronze sail
#

yes

#

nvm

#

i see problem in my solution

#

😦

#

im blind hah

agile sundial
#

darn

bronze sail
#

heh

drifting drum
#

What problem are y'all talking about? Sounds interesting

calm spindle
#

hello

#

is there a alternative for sly module??

#

ping me on your reply

mint jewel
#

lark can do something quite similar, if you specifically want lex+yacc, afaik sly is the main project for that

calm spindle
#

yeah I want lex and yacc

#

we need to code our own ast write?? @mint jewel

mint jewel
#

ye, seems like that is the standard way. lark afaik can do it on its own, as can antlr4, but those are not lex yacc

calm spindle
#

did you mean lark-parser??

mint jewel
#

ye, lark parser

calm spindle
#

can we even do lexing in it??

#

@mint jewel ??

mint jewel
#

I would think so

#

yes, you can

#

you can even use custom lexers

calm spindle
#

thanks for all the info you gave @mint jewel

frozen ermine
#

Hello

#

Anyone can help me

calm spindle
#

come up with your problem first dude

frozen ermine
#

I need some help related to grammer portions

#

Of My Exam

calm spindle
#

what??

frozen ermine
#

πŸ˜…πŸ˜…

#

Wait

fiery cosmos
#

this is a developr discord server

calm spindle
#

@fiery cosmos you're right

zenith pasture
#

It’s fine to ask questions about grammar here as long as they are related to formal grammars or part of language theory which is a part of compsci

fiery cosmos
#

what type of grammar are you talking about

calm spindle
#

lexing and parsing??

fiery cosmos
#

BRUH

calm spindle
#

@mint jewel where can I find a tutorial on lark

fiery cosmos
#

can somebody say me what exactly should i learn to implement python codes to any microchip?

#

please ?

mint jewel
marble basalt
#

What microchip do you have

fiery cosmos
#

does anyone know how to do a command in a bot dm instead of doing it in a channel? so like do a !help command by dming the bot and it shows u the message in the dm

marble basalt
#

Don't post in multiple channels please

bronze sail
#

@drifting drum I had a tree, and want to find out if graph is sequential or has some loops in it

marble basalt
agile sundial
#

smfh don't just give out solutions like that

#

jester, it was just find out if a directed graph is cyclic

#

like that link, lol

marble basalt
#

I mean its basically just knowing the algorithm

agile sundial
#

Β―_(ツ)_/Β―

bronze sail
#

got it

#

I just had to hold algorithm till routs join again, so I can inspect node only once πŸ˜„

trim mantle
#

Good night people!
Someone can help me?
I need know a good way to process images for a classifier algorithm

dusty cipher
#

Thanks@public

agile sundial
#

what

fiery cosmos
#

g'

fiery cosmos
#

list vs set vs dict.

sly bronze
#

I have an array of first name + last names, such as ['John Smith', 'Bob Marley', 'George Vaught']. Is it possible to extract an array containing the first names only?

#

I can get a vector holding the position of the last letter of the first name with str.find, but I don't know how to process from there

#

Also I'd like to avoid a loop if possible

#

.str.split(' ').str[0] is what I needed

agile sundial
#

not sure how you'd do it without a loop

#

but you can use a list comp like so

[name.split()[9] for name in names]
sly bronze
#

Thanks

#

How do I add them back together? I have array ['John', 'Bob', 'George'] and array 'Smith', 'Marley', 'Vaught' and I want to get back the array of full names

agile sundial
#

zip

agile sundial
#

?

silk knoll
#

Stop spamming if you don't have anything meaningful and on-topic to say

candid osprey
#

How do I add them back together? I have array ['John', 'Bob', 'George'] and array 'Smith', 'Marley', 'Vaught' and I want to get back the array of full names
@sly bronze if your end goal is this, just simply start with your initial list (try to not call them arrays in python, arrays mean something else) and just use the split. [name.split() for name in names]

quasi oracle
#

!warn 740995019049009203 don't spam random nonsense

halcyon plankBOT
#

:incoming_envelope: :ok_hand: applied warning to @fiery cosmos.

fiery cosmos
#

Hi guys. So this is by no means high level, but I was wondering if anyone could help my understand this a bit better:
I'm working on a little project where I use the BungieAPI to calculate some statistics for the PvP side of the game. A common metric for PvP games is the K/D (Kills / Deaths) ratio. My goal is to calculate the mean K/D of all players. However, many players believe that the mean K/D is 1.0 because every death is caused by a kill. I'm struggling to grasp how that makes sense as the arithmetic mean. The K/D values is a fraction, the the previously mentioned calculation is basically just the sum of numerators divided by the sum of denominators, which isn't anything like the equation for population / sample mean?

calm spindle
#

how to import lark-parser

#

Traceback (most recent call last): File "C:\Users\Manoj Kumar\Desktop\LARK.py", line 2, in <module> from lark import Lark, logger ImportError: cannot import name 'Lark' from 'lark' (unknown location)

#

this is what I get when I tried

silk knoll
#

Is there a specific name for this sort of tree notation? a{b{c{d{e{}}...

drifting drum
#

jester, it was just find out if a directed graph is cyclic
@agile sundial right, what was the idea y'all finalised upon? Feel like it's sort of a dfs question but that almost feels like brute force
Maybe bfs?

agile sundial
#

just normal dfs, if you encounter a visited node, the graph is cyclic

fiery cosmos
orchid crypt
#

I’ve been reading that book recently, it’s quite good. Can recommend.

fiery cosmos
#

Interesting

#

First time ever I see any developer online do a book

inner horizon
#

can anyone help me with my js problem?

#
function makeInviteCode() {
    $.ajax({
        type: "POST",
        dataType: "json",
        url: '/api/invite/how/to/generate',
        success: function (a) {
            console.log(a)
        },
        error: function (a) {
            console.log(a)
        }
    })
}```
#

i wanna know what it does

fiery cosmos
#

Makes a list and checks for error, using Ajax?

inner horizon
#

idk

#

thats why im here

#

whats that url for then?

fiery cosmos
#

No, that's my answer

inner horizon
#

then whats that url for?

#

and the datatype?

fiery cosmos
#

No idea

#

Never used Ajax

inner horizon
#

unpacked it tho idk if it will work or not tbh

#

the real code is more mind strssing

#
eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('0 3(){$.4({5:"6",7:"8",9:\'/b/c/d/e/f\',g:0(a){1.2(a)},h:0(a){1.2(a)}})}',18,18,'function|console|log|makeInviteCode|ajax|type|POST|dataType|json|url||api|invite|how|to|generate|success|error'.split('|'),0,{}))
#

here

fiery cosmos
#

Yea I'm gonna pass xD

oblique panther
#

this is javascript? that would be more appropriate for one of the off-topic channels.

inner horizon
#

yeps aight bet

silent girder
#

def bubble(sorted_list):
  for i in range(len(l1)-1):
    swap = False
    for i in range(len(l1)-1):
      if sorted_list[i] > sorted_list[i+1]:
        sorted_list[i], sorted_list[i+1] = sorted_list[i+1], sorted_list[i]
        swap = True
    if swap == False:
      return sorted_list
  return sorted_list

print(bubble(l1))```
#

I asked in advanced bc this is advanced for me lol

agile sundial
#

so, the reason this is really slow, is you check every element against every other element

#

which means that if if you have a list of 100 items, you have to check 100*100 things

silent girder
#

I think I get it don't check the last item

#

each time the list gets shorter

agile sundial
#

right, when you find the biggest number, and move it to the end, you don't have to check it anymore

#

it's in the right spot and won't move anymore

silent girder
#

let me see if I can code that thank you

#

I think this will work ```l1 = [6,1,3,2,7,9,10,5,4,8]

def bubble(sorted_list):
amount = len(sorted_list)
for i in range(len(l1)-1):
swap = False
amount -= 1

for i in range(amount):
  if sorted_list[i] > sorted_list[i+1]:
    sorted_list[i], sorted_list[i+1] = sorted_list[i+1], sorted_list[i]
    swap = True
if swap == False:
  return sorted_list

return sorted_list

print(bubble(l1))```

agile sundial
#

i'm pretty sure you'll get index out of bounds for that

#

!code also, can you use

halcyon plankBOT
#

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:

```python
print('Hello world!')
```

Note:
β€’ These are backticks, not quotes. Backticks can usually be found on the tilde key.
β€’ You can also use py as the language instead of python
β€’ The language must be on the first line next to the backticks with no space between them

This will result in the following:

print('Hello world!')
silent girder
#

I used that didn't I

#

I don't get index out of bounds because I subtract at the beginning

#

it took 39 iterations to sort

gaunt forge
#

This is an aside, and some people disagree with me, but I think Python is a rubbish language for teaching compsci in

silent girder
#

There are certainly more resources for java but python is friendlier

gaunt forge
#

Offhand that looks legit though

#

Yeah, but it's Python's friendliness that causes issues when learning the fundamentals. Python is designed to let people code programs quickly without knowing the fundamentals

#

But I digress

agile sundial
#

also, on every iteration, you are guaranteed to move at least 1 number to the right spot

#

which means you don't need to check if it's done at the end

silent girder
#

meaning just iterate it so many times?

agile sundial
#

what?

silent girder
#

i don't know am I checkking at the end?

gaunt forge
#

I don't think he's checking if it's done at the end, he's saying that if he has an iteration in which he doesn't perform any swaps then he's done

#

Although

#

Is that true?

agile sundial
#

if you don't perform swaps you're done yeah

gaunt forge
#

okay

#

Oh right, yeah

#

I was thinking of insertion sort for a second

agile sundial
#

hm, so that would be helpful nvm

silent girder
#

Oh i see

#

wait I lost it

#

I'm a noob lol

#

bc of python I have been able to code alot without the fundamentals lol

agile sundial
#

that's pretty bad

silent girder
#

so now I'm trying to learn them

agile sundial
#

sorting isn't really a fundamental though

silent girder
#

data structures and algorithms

#

I'm taking a course on Udemy

#

I'm a machinist in my normal job

gaunt forge
#

Idk, I'd say bubble sort is part of data structures and algorithms

#

It's like, the most basic of basic

#

Good job on self-learning btw

silent girder
#

thanks

#

I just did a random list of 100 and it took 4872 iterations

#
from random import randint

l1 = [randint(1,100) for i in range(100)]

def bubble(sorted_list):
  amount = len(sorted_list)
  counter = 0
  for i in range(len(l1)-1):
    swap = False
    amount -= 1
    
    for i in range(amount):
      counter += 1
      if sorted_list[i] > sorted_list[i+1]:
        sorted_list[i], sorted_list[i+1] = sorted_list[i+1], sorted_list[i]
        swap = True
    if swap == False:
      return sorted_list, counter
  return sorted_list, counter
print(bubble(l1))
#

I can't get it to !code

agile sundial
#

what?

silent girder
#

oh It's just syntax highlighting?

agile sundial
#

yeah

silent girder
#

Thanks alot for your help