#algos-and-data-structs
1 messages Β· Page 84 of 1
the course sylabus looks like this
I have a design patterns course to do next
I would use the python built in sort or sorted function myself lol
When you're using bubblesort, it's generally with the assumption of 1) small data set 2) mostly pre-sorted
and because you're really tight on memory constraints
ehh what about insertion sort
worst case is the same as bubble, but on partially sorted data it's much faster
I was hoping I could do a reverse with an eval statement py def bubble(sorted_list, revers=False): if reverse: direction = eval('<') else: direction = eval('>') amount = len(sorted_list) counter = 0 for i in range(len(sorted_list)-1): swap = False amount -= 1 for i in range(amount): counter += 1 if sorted_list[i] direction 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
I did it!py def bubble(sorted_list, reverse=True): if reverse: direction = operator.le else: direction = operator.ge amount = len(sorted_list) counter = 0 for i in range(len(sorted_list)-1): swap = False amount -= 1 for i in range(amount): counter += 1 if direction(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
you could also reverse by changing the sign of every element
I think the current solution is the preferred one, using negation would make it unable to sort lists of non-numbers
yeah
I think insertion sort and bubble sort are roughly equivalent. They're both 
No, no UC, sometimes when you're forced to be in-place it's not terrible
on small datasets
right - Big O is all about how performance changes as the data set grows. For large datasets, insertion sort is terrible. For small ones it can outperform other algorithms.
talking about algos
I was looking at the maximum subarray sum problem and came up with an algorithm but I'm not sure it actually works. I came to a proof that more or less works but there are details to work out
but I also don't want to reinvent the wheel
has anyone heard of a solution like this? basically my idea is to take contiguous terms of the same sign and merge them (add them into a single value) and then also check sequences like +-+ or -+- and also add them up under certain conditions
also I independently invented bubblesort in my first year at uni lmao my prof wasn't impressed
so I made a selections sort now ```py
def selection_sort(iter_nums):
swap = True
marker = 0
count = 0
while swap:
swap = False
marker += 1
for idx, num in enumerate(iter_nums[marker:]):
if iter_nums[idx+marker] < iter_nums[marker-1]:
count += 1
iter_nums[idx+marker], iter_nums[marker-1] = iter_nums[marker-1], iter_nums[idx+marker]
swap = True
return(iter_nums, count)
l1 = [2,10,8,5,3,1,9,6,4,7,]
print(selection_sort(l1))
it takes half as many iterations as the bubble sort I made last night
strange thing is happening though sometimes its not working just sorting a random generated list with randint
so with insertion sort, it's possible to not make any swaps
i think
ah if part is in sorted order
tbh i'm probably wrong about everything
...wrong language...
and ? none of yall know c?? π
that's also homework too
scanf("%d %d %d", &*p, &*q, &*r); is the troublesome line, you cannot dereference uninitialized pointers
and ? none of yall know c?? π
@vapid dagger I think a fair number of us know C, but why would you ask for C help on a Python server...?
@vapid dagger like mentioned this is a Python server. You could discuss your C problem in an off-topic channel, but there are servers for C
I think I really have it this time ```py
l = [6, 8, 1, 4, 10, 7, 8, 9, 3, 2, 5] # original case
count = 0
def my_insertion_sort(iter_list):
def swap(iter_list):
for num in range(1, len(iter_list)):
global count
count += 1
if iter_list[num] < iter_list[num-1]:
iter_list[num], iter_list[num-1] = iter_list[num-1], iter_list[num]
reverse_swap(iter_list, 1, num)
continue
def reverse_swap(iter_list, start, stop):
global count
for num in range(stop, start-1, -1):
count += 1
if iter_list[num] < iter_list[num-1]:
iter_list[num], iter_list[num-1] = iter_list[num-1], iter_list[num]
continue
swap(iter_list)
return(iter_list, count)
print(my_insertion_sort(l))```
I'm working on a pixel art editor in tkinter and was wondering what a good way to export the current image was, it uses frames with bindings rather than a canvas widget for the canvas space, I have a way to scan the cells and make a matrix containing the pixel color values in html notation but don't know of a good way to export to a standard file type
print("Hello Discord")
how do i write this syntax so it works:
print("Invalid input. Number must be between 0 and 10")```
if 0 > int(user_input) or int(user_input) > 10
thank you
One message removed from a suspended account.
Not sure if you actually wanted to take input twice or not though
Logically that seems wrong
import pickle
def write():
f=open('file.dat','wb')
record=[]
while True:
roll=int(input("enter roll no: "))
name=input("enter name: ")
marks=int(input("enter marks: "))
rel=[roll,name,marks]
record.append(rel)
ch=input("do u want to add more records? ")
if ch=="n" or ch=="N":
break
pickle.dump(record,f)
f.close()
def update():
new=[]
ask=input("do you want to update? ")
if ask=="y" or "Y":
obj=open('file.dat','rb+')
roll=int(input("enter the roll number: "))
name=input("enter name: ")
new_marks=int(input("enter the marks to be updated: "))
latest=[roll,name,new_marks]
new.append(latest)
pickle.load(obj)
for i in obj:
if i[0]==roll:
del i[3]
pickle.dump(new,obj)
print(i)
print("updated")
else:
print("nope")
obj.close()
write()
update()```
i am trying to write and update a binary file here...the writing part works fine..i need help with the updating part.
while writing into the binary file, i have used a "roll" input. After it gets written..i use that "roll" to identify the list in the binary file..and also i have written pickle.load(obj) before. With this..i want to update the marks in the list.
should i use 'ab' as the mode?
Hello -
I want to do Computer Science in Uni and get a degree but i don't know if i am good enough or smart enough to do computer science
I don't know if i should
any advices on what paths i should take or anything?
I've just started a degree in CS myself. I think it's a good option because it's relevant and in demand, but it can be quite challenging. It can be quite heavy in terms of mathematics, so that's something you need to be aware of - even though I'm not very good with maths I'm enjoying it so far. I just have to work very hard to keep up with it.
hmm i see
You can start studying CS regardless of whether you'll go to uni in the end. Plenty of resources online
yeah that's true. There are plenty of free courses and resources available
is it really heavy on math
so far i haven't seen anything difficult in terms of the math
But difficult is a subjective term, right? π
There's quite a bit of math in CS. Depending on the institution, you might be able to minimize the amount of math you do in your degree, but as a field there's plenty of math
The most difficult math is some of the discrete and boolean stuff imo. Those can be quite important depending on what you work on. The difficulty in em lies in that it is quite strange math, not very similar to what you are used to from regular school math.
i could see that
i liked the math that i've done so far -- the boolean and even statistics (altho i could do without that last one lmao)
statistics is super important if you are going into data science though
Depending on what you choose to specialize in, probability theory and statistics might be very important
ooooof
I made the mistake of not paying much attention to my stat classes and I am eating that up now
damn, i was half awake during my stats classes too lol
statisticians can be increadibly boring xD
facts lol
it gets a lot more interesting when you start with applications of it (data science and ML). You need to have a firm grasp of the fundamentals by that time though
Math really isn't my strong suit, and just done a degree in psych so it's been a while since HS for me. I'm doing discrete mathematics atm and it's isn't too hard I guess. I just need to work hard at it to keep up
yeah I've heard the ML stuff is heavy on the math side
ML would be pretty sick to learn
In theory, yes. A lot of contemporary ML is using the libraries developed by others
interesting
You can use ready-made tools as building block to create some pretty decent applications. If you want to do more advanced stuff and create something entirely of your own you would need to know a lot of the underlying theory, yes
You still need a statistical understanding even if you are using libs. The reason is that you need to shuffle the data correctly into the libs and you need to be able to understand the results that come out properly. Debugging ML stuff without understanding the statistics of it is a painful experience.
Otherwise you will get results like many of them failed AI scandals (AI identifying a gorilla as a black man and such)
I recently found this awesome yt channel that explains statistics in a very good way. This is gold for people that wanna do ML and Data science
https://www.youtube.com/user/joshstarmer
Thoughts on the books clean code and the pragmatic programmer? Iβm a self-taught programmer and I still consider myself a beginner. I do some basic data science/machine learning but I wanna learn more computer science concepts. Are those books good for beginners? Are there any books you can recommend?
read PEP8 for one
thats styling, but it will prevent you from making people cringe when they read you code @balmy yacht
learn to use things like list comprehensions and generators, seeing a for-loop when a list comprehension should have been used or an explicit list when a generator is possible is un-"pythonic"
the lists comprehensions bit is mostly stylistic, but using generators is more memory efficient
Ohh I should read that, yeah. Thanks!
anyone here good at regex?
re.compile(fr"(?sm)<DOCUMENT>\n<TYPE>{FORM}(.*?)</DOCUMENT>")
i've got this
and FORM is currently a string
but I would like to make it a list and have it match anything in the list
could I do something like
re.compile(fr"(?sm)<DOCUMENT>\n<TYPE>(?:{''.join(FORM)})(.*?)</DOCUMENT>")
I'm not sure I understand the problem properly but can't you just iterate through FORM and pattern match on each element?
yes, i was hoping to just get it in one line though
trying to match an html section like this
<DOCUMENT>
<TYPE>N-1A/A
where FORM=['N-1A','N-1A/A']
When it comes to regex they should be made as simple as possible imo. My personal opinion is that a loop with comments explaining what you do is more maintainable than a single line which packs a lot of different operations into one expression.
There might be some function in the re module for searching in lists though, might be worth taking a look
what i sent actually works haha, but i see what you are saying
i have like 10 regular expression right now and some are kinda nasty
not-lookbacks and all that
Most developers don't work that much with regex so the competence is generally not great. Therefore us that do work a bit with regex have to take some pains to make it understandable for our fellow colleagues π
Yeah, I know exactly what you mean. I was doing some regex pattern matching in our test frameworks and people have written the tests in completely different ways. So coming up with a regex pattern that caught all variations was extremely painful. A simple thing that would have solved the issue was to implement a coding standard that people had to follow.
i'm pulling millions of documents from the SEC's website and certain things are uniform, but other things are just awful
and there is no way to verify that i am getting good coverage because there are just too many documents to check haha
yeah that is a tough nut to crack. I know there are specific libraries built for data cleaning if that could be of any use. Never dabbled with em myself since I have not been in a situation where manual cleaning did not work.
there are, but i cant have much overhead using BeautifulSoup or whatever since i dont want this to run forever
so therefore regex
hmm, might be difficult to guarantee good coverage then.
yeah, but even using more sophisticated libraries would only do so much
it would require training a ml model to actually be confident in coverage
I am trying to learn classes, I want to print the value I get from def meanvel(self):
I did this without using classes
but I want to familiarize myself with classes
and start using them
but I keep getting this error
def init instead of ininit might do it
import numpy as np
def sequence_cut(x):
sum_half = x.sum()/2
temp_sum = 0
y = np.empty(0)
for value in x:
y = np.append(y, value)
temp_sum += value
if (temp_sum >= sum_half):
return y
main_array = np.array([2, 3, 1, 1, 4, 5, 23, 6, 3, 40])
cut_array = np.array([2, 3, 1, 1, 4, 5, 23, 6])
print(sequence_cut(main_array))
print(cut_array)
Why does my function produce a different looking array?
most functions have dtype=float by default
including np.empty
btw, you should not use np.append like this
def sequence_cut(x):
sum_half = x.sum()/2
temp_sum = 0
y = []
for value in x:
y.append(value)
temp_sum += value
if (temp_sum >= sum_half):
return np.array(y)```
using a list will give you much better performance as x grows
(np.append is not a cheap operation, unlike list.append)
^
in general, numpy and pandas attain their speed increases because the data are fixed-length and fixed-type
that lets numpy compile functions underneath python
so if you are going to be doing lots of appending, numpy is going to have trouble
Numpy and pandas are written in C/C++ and that is why they are so fast. Python have a very good interface for calling compiled code from within python interpreted code.
Python is slow
if you compare cpu intensive tasks, then yes. otherwise, not really
If you keep it in a predefined format with predefined options, you could write a parser for it
The start would probably be having a good grasp on string processesing
i think there's an "english" programming language floating around somewhere
yeah you'd have to tell it how to recognize the commands you're giving it
would AI and machine learning fit in this channel?
actually yeah, so i have a question about Chatterbot, the python library
i tried tensorflow but it doesnt support my gpu
so i had to drop that
i started working on a little chatbot and first thing i did was download a month's worth of reddit comments, to train the model on that
i parsed everything into 2 files:
one file contains the original messages and the other contains the most upvoted reply.
i have about 100000 lines worth of message data
and i wanted to start getting to work on my ai model
but tensorflow doesnt work with my gpu so i looked into chatterbot
what i want to know is if i can train a model i make with chatterbot using the datasets i created
no, tensorflow is used for neural networks mostly but it does have the ability for language processing
at least as far as i know
so does anyone know if chatterbot can do that
to train a model off specific datasets instead of just talking to the user because that will take much longer in my opinion
!mute 704193520373596222 3d trying to ping 90k people to advertise whatever pyramid scheme you're managing is unwise
:incoming_envelope: :ok_hand: applied mute to @fiery cosmos until 2020-08-23 19:58 (2 days and 23 hours).
@strange merlin i donβt really know about Chatterbot but there is this great dialogue system library which uses pytorch and has a bunch of state of the art models called ParlAI.
It can be trained with custom datasets too
nice
@strange merlin great idea tho
@strange merlin great idea tho
@fiery cosmos which one?
reddit thing
ahh
yeah
i used only a month's worth tho
there were datasets from 2007 all the way through 2019 i think
but the files were wayyyyy too large
a month was 1.2gb with .xz compression
thats how u get started tho, and the point is chatbot must learn from chatting
yeah
of course
but i wanted to train it off the data first then it can start learning by talking with people
I have a dict object mapping key,value pairs in the format int:set(tuple) and I want to get the key,value pairs of subsets with the same value, how would I go about this?
e.g.
map = {1:{(1),(2)}, 2:{(1)}, 3:{(1),(2)}, 4:{(1)}}
and I want to return something like
{1:{(1),(2)},3:{(1),(2)}}
{2:{(1)}, 4:{(1)}}```
I've tried using functools.reduce but I'm not entirely sure what my lambda function should be in the first argument
Thanks
i think you just have to check them all
damn, thats what I was trying to avoid, thank you
!e
from itertools import groupby
map = {1:{(1),(2)}, 2:{(1)}, 3:{(1),(2)}, 4:{(1)}}
groups = [ dict(group) for _, group in groupby(sorted(map.items(), key = lambda x: x[1]), key = lambda x: x[1])]
print(groups)
You are not allowed to use that command here. Please use the #bot-commands channel instead.
sort, by the value, then use groupby to break it up, same key kwarg
okay thats really good, thanks
You might benefit from frozebsets as they are hashable. Might allow you to avoid sorting
Logically, simply printing out the results will force you to go over each item, so you can't do any better than that
let me know if this is the wrong help channel I'm new to python and have been trying to figure out what I did wrong. It read the True or false on vacation but it wont read the range number right so that I could get the else print on range(1,6)
it looks like you set
day = wakeUp[0]
on line 2, so when when the function is entered on line 15 and it reaches line 11
day = "Sun"
i.e. you've set the variable day to the String value "Sun" so the if statement will not be true on line 11
if you're new to programming in python I would recommend you learn your way around an IDE (integrated development environment) for python I use PyCharm but there are others available. Using an IDE will allow you to set breakpoints in your code (places where you can pause your script) and let you inspect the value of variables while your program is paused
Ok cool I'll check it out thanks for the help
a way to fix your code would be to replace line 11 with either
if day == wakeUp[0] or day == wakeUp[6]:
or
if day == "Sun" or day == "Sat":
I just finished a half a course on data structures and algorithms I built this analyzer to test all the functions for time how would I check for complexity and could I improve the code at all https://github.com/g4m3rm1k3/data-struct-algo-s
the only ways to test for complexity are to either: 1) think about it or 2) plot a bunch of data and do a regression
you could look up average case time complexities for your algorithms and compare
if yours are worse, you can improve them
I dunno if my question fits into this channel too, but I sent it in #data-science-and-ml anyway, https://discordapp.com/channels/267624335836053506/366673247892275221/746555783344422922
( I moved my question to #help-peanut )
is there an algorithm that can find k highest elements of an iterable in a single iteration
I know you can sort/partially sort with selection sort, but neither is all that great
is there an algorithm that can find k highest elements of an iterable in a single iteration
@mint jewel use a heap with max sizekand iterate through, popping from the heap whenever a value higher than any in the heap is found?
am I misunderstanding the problem
author = ctx.message.author
avatar_url = author.avatar_url_as(static_format = "jpg")
read_avatar = await avatar_url.read()
print("avatar read")
bytes_converted = io.BytesIO(read_avatar)```
how do I convert the bytes_converted file to an jpg here? pls help
does this q belong here?
isn't there nlargest or nsmallest in the heap module
oh but creating the heap is O(nlogn) still
heap with max size k would work
but yeah, think you're stuck with O(nlogn), since sort approach is also O(nlogn)
heap has a disadvantage of space too, so quicksort probably best bet
there is quick select too
works like quicksort average complexity is O(n)
worst is O(n**2)
actually would heap solution be O(klogk + n)?
depends how you are doing it ig
first select the k elements of array and build a max heap
how are you gonna select those elements lol
the first k elements
just in any order
then for the other elements
compare it to the root
if it is greater than make it the root
else ignore
ur heap will have find-min as well as find-max at O(1)?
no normal max heap
it does
[4,3,2,0,1] , start with 4, so heap:{4, 3, 2, 0}?
what do you wanna find
find-max would return 4, 1 is not greater than 4, so your result would end up being 4,3,2,0, right?
the kth largest or smallest?
big brain
big brain time
easier to code probably during interview too
compared to quickselect
fuck that shit LOL
i'd be very surprised if you weren't allowed to use builtin heap
lol rip
I've never coded quickselect myself but it seems similar to quicksort
from what i've read in the past minutes or so it's very similar
its not that hard
you just need to get a hang of recursion
trying solving recursion problems on leetcode
hm what about graphs and trees
i am new to phython
i used to work with javascript
but heard phyton better for game dev
so decided
to shift
what kind of games are you looking to develop
but heard phyton better for game dev
better than js maybe but not in general
python might be too slow for anything beyond 2d
oh i see
JS has the advantage in having browser as the distribution platform, and is also much more performant. For gamedev, C#, C++ and haxe seem to be the languages of choice novadays
python is quite nice, but you may run into performance problems quite soon
there are some libraries (ei: pyglet) that use OpenGL (C++?) but generally you won't be able to 3d render well
ya
by far, the JIT is insane
jit?
it is almost C speed in some cases
so what makes webpages so slow sometimes? it cant just be the downloading of images
and other content
thats only a few hundred mb at most
a ton of dynamic JS will still be slow
i used js, cs and c for 7 years now
use unity
Hello?
We share the ownership with three people
There's no reason to ping owners for that
?
sorry if i disturbed you
pygame is used for game dev
i use multple devs
but python is slow man
dynamic language meaning?
If you want 2d use arcade
You donβt have to specify a variables type/you can change it
Learn Python in this full tutorial course for beginners. This course takes a project-based approach. We have collected five great Python game tutorials together so you can learn Python while building five games. If you learn best by doing, this is the course for you.
π₯ Learn...
try this tutorial
it will help
So like:
a = 5
a = str(a)
a = list(a)```
yes i am downloading it
Whereas in a static language you would need:
int a = 5;
``` and canβt freely change the type
?
can someone help in a python program?
i need to create a program to find the maximum 3 values from a dictionary.. how to do it.. without importing any inbuilt module type thing?
Uh... um... hmmm. I actually haven't touched dictionarys that much so...
Im sure there is someone around here who has tho.
i have done in it class 11- but now in 12 i m not much thorough with it-i seached google
but in google everywhere its inserting some module
Hey! This is not really that related to computer science, but a few days ago i encountered a problem with tensorflow because I dont have a supported GPU so i dropped the tensorflow idea. now i keep hearing about google colaboratory but it never occurred to me that i might be able to do all my coding there and all my testing there because technically i wouldnt have to install tensorflow on my machine. do you guys think it would work on google colaboratory?
Why not take a .values and sort the dict
thats y i asked before asking this question
Hey! This is not really that related to computer science, but a few days ago i encountered a problem with tensorflow because I dont have a supported GPU so i dropped the tensorflow idea. now i keep hearing about google colaboratory but it never occurred to me that i might be able to do all my coding there and all my testing there because technically i wouldnt have to install tensorflow on my machine. do you guys think it would work on google colaboratory?
@strange merlin
Take the top 3 after sorting
Hey! This is not really that related to computer science, but a few days ago i encountered a problem with tensorflow because I dont have a supported GPU so i dropped the tensorflow idea. now i keep hearing about google colaboratory but it never occurred to me that i might be able to do all my coding there and all my testing there because technically i wouldnt have to install tensorflow on my machine. do you guys think it would work on google colaboratory?
@strange merlin yes, should work fine
guys i made a program to get me roots of a quadratic equation but the issue is i want answers in fraction instead of decimals, how do i do that ?
you can either use sympy, or use the builtin fractions.Fraction, but that will not let you make a fraction with irrational parts
Output and explain ???
don't think it matters how much memory u give a VM (in terms of effecting ur actual computer)
i'd say give urself enough to run whatever you are planning to on the VM
I mean it does matter, your computer will have less memory available to it
12 GB is a ton of ram for a VM, what are you running
@fiery cosmos for future reference #unix or #tools-and-devops would be more ideal
my linux prof lied to us π¦
@fiery cosmos sue them
The instructions are on #βο½how-to-get-help
I think what your professor means is that if you give it less ram than it needs it will just struggle or crash. Its okay that the host has less memory because it allows the guest to run properly
12GB is a LOT for a vm
how do i use a virtual env? and should i?
@sharp ore you can use the venv python module
hey, is there a way to loop a python code a certain amount of times?
basic example: you rolling a dice, and you want the players to have 5 rounds, is there a way to loop the random code 5 times before ending?
A for loop?
for i in range(5):
print(i)```
will print
0
1
2
3
4
everything in the indented block is what is iterated
hmmm ok
anyone know where I can get free malware samples for testing?
hello .... i wanted to learn selenium with python ! is there any good free resource to learn it ?
You are not allowed to use that command here. Please use the #bot-commands channel instead.
@elfin sage try asking in #web-development
@elfin sage Selenium is more closely aligned with web development than it is with computer science
ahh shit ! i didnt notice i asked in computer science
@oblique panther thanks a lot bro !
ππ»
what is macro
what is macro
@fast stream You mean computer macros? Consider them to be set of instructions to be executed or carried out in a certain order. They are scripts so when you run it, it would execute these instructions.
@fast stream You mean computer macros? Consider them to be set of instructions to be executed or carried out in a certain order. They are scripts so when you run it, it would execute these instructions.
@zenith pasture oh thank you very much
i have a question ..i have an array that looks like 1 2 2 1 3 3 ...and i want to write it like 1 2 3 1 2 3 do i have a function for it in python?
what does it do for other arrays?
that is either a really cool looking painting or a baby in a womb... i can't decide
im still a beginner at python, how do i use a while true loop anyone ;-;
having to ask online since there hasnt been classes due to corona
while True:
# code right here
do you mind if i explain my code to u
go ahead
basically, ive made this dice game
wheres theres 2 players who roll 2 dices 5 times
ive done all the actual dice rolling and things
aren't you the guy who posted "how to use a for loop"
lol okay
so like, if a total score of the 2 dices is even, score=score+10
if total score of the 2 dices is odd, score=scre-5
at the end, if the 2 players have the same score, they have to keep rolling until 1 beats the other
like this is the bit i dont understand, how do i use the while true to keep looping until 1 beats the other?
at the end i assume both players get a chance to roll?
yea
this will work however i don't think they both get a chance to roll
while score1 == score2:
...
never mind they will both get a chance
but what if they both roll even or both roll odd ._.
while score1 == score2:
roll_for_player_one()
roll_for_player_two()
then it will keep looping/rolling
yes but my dice=random.randint(1,6)
once that loads once, it stays with whatever number it already has
so wouldnt just produce the same numbers over and over again
well yes
dice = random.randint(1, 6)
but my dice codes kept giving me the same
just over and over again
dice1 and dice2 aren't going to call random.randint(dmin, dmax) every time
they are being set once to that
yea i changed it to (1,6) later
actually i had 1,6 orginally, the variable spammed 2 and 3, which is why i changed to dmin and dmax hoping for change
after i changed it, it spammed 5, 3 instead of 2, 3, to solve this i just made seperate variables for every dice rolled
>>> import random
>>> dice = random.randint(1, 6) # dice is set to a random int
>>> dice
2
>>> dice
2
>>> dice = random.randint(1, 6) # dice is set to a random int
>>> dice
1
my pleasure.
btw how do you type like that
```py
>>> import random
>>> dice = random.randint(1, 6) # dice is set to a random int
>>> dice
2
>>> dice
2
>>> dice = random.randint(1, 6) # dice is set to a random int
>>> dice
1
```
it's backticks
this character `
π
last question
how do i use external file codes when im using an online editor (repl.it) to run python ._.
if you import stuff that isn't listed in your files menu it will search for this stuff somewhere and install it. it does it at the start of the program, it takes time to install "dependencies"
uhhhh what?
for god sake it does all the magic when it starts the program
im gonna have to get this right first try, cause i dont think i can test ;-;
if you're using standard libraries it's not going to install anything new, but if you're using external libraries it's going to try and search for it and then install it
import random & import time will work if that's what you're wondering
i dont understand these high tech terms
im just a schoolboy in england whose trying to do home learning during corona crisis ;-;
still new to python
anyways i wont bother you any longer, thx for your time, enjoy the rest of your day π
thank you
@fresh mulch
Python is a language that comes batteries in
Which means there is a standard library
Like let's say math or time
But there are still external libraries that you can install with pip
This editor does it for ypu
oh ok
Hi,i just have a doubt that lists in python are analogous to arrays,then what are singly linked lists in python(i know deque is doubly linked list)
good to know
@leaden monolith unless you write your own there aren;t any
although generators behave similarly
there's llist
Is there a set operator that returns the number of elements in a set?
I mean like a specific mathematical notation, not how to do it in python
||
Cheers
Admittedly, they all mean about the same - some kind of measure π
import itertools
import pygame as pg
pg.init()
BLACK = pg.Color('black')
WHITE = pg.Color('white')
screen = pg.display.set_mode((800, 600))
clock = pg.time.Clock()
colors = itertools.cycle((WHITE, BLACK))
tile_size = 20
width, height = 8*tile_size, 8*tile_size
background = pg.Surface((width, height))
for y in range(0, height, tile_size):
for x in range(0, width, tile_size):
rect = (x, y, tile_size, tile_size)
pg.draw.rect(background, next(colors), rect)
next(colors)
game_exit = False
while not game_exit:
for event in pg.event.get():
if event.type == pg.QUIT:
game_exit = True
screen.fill((60, 70, 90))
screen.blit(background, (100, 100))
pg.display.flip()
clock.tick(30)
pg.quit()
@rare shadow take a look at #game-development if you're interested in that
def topKFrequent(self, words, k):
count = collections.Counter(words)
candidates = count.keys()
candidates.sort(key = lambda w: (-count[w], w))
return candidates[:k]```
A bit confused what's going on with the lambda function
@primal dock when you sort tuples, it will first sort by the first position. If two tuples are equal in it, it will order them by the second position, and so on
So it sorts by the count in reverse (hence its negative), and then by the word itself
Thank you!
usually means a firewall issue
Also there is no reason to censor your private ip address, its meaningless to anyone not in your network
hi, is anyone explain how to check is bipartite or not
hi, is anyone explain how to check is bipartite or not
@maiden moon sorry, could you rephrase that?
well i am trying to determine the graph is bipartite or not
@brave oak i got some edges and node numbers
oh, a graph
you missed that word in your original question I think
can you use a library?
or do you have to do it with just an edge list
in Python
@brave oak i am a newbie and dont understand any of it. It is so frustrating
@brave oak just a python
do you understand how graphs work?
@brave oak enlighten me please
hm I'm not really sure if that's within the scope of this channel but okay
so basically a graph is a collection of nodes (points) and edges (lines)
okay
you can use graphs to model connections between objects
super good example, social media
your Facebook can be modelled as a graph, where nodes are people and edges are friend relationships
the edges can be undirected, as in this case (if I am your friend, you are my friend)
or directed (meaning a line goes one way)
to model Instagram as a graph, you need a directed graph, since I might follow you without you following me
but I believe your question is about undirected graphs
so, do you know what a "bipartite graph" is?
I perceived it as, node which has 2 edges and once node has 2 edges it can not create edge with others
@brave oak maybe i understand it wrong
i am a student
so it's for school?
yeah, whole concept is fairly new to me.
okay, I feel like your school is not teaching you properly...?
plus language difficulty is the problem i guess
but anyway let's continue
basically, a bipartite graph is a special kind of graph
where you can split nodes into two groups
and there are only edges between members of different groups.
does that make sense to you?
so that means, once node in a specific group can not have edges in same group?
edges to other nodes in that group
okay, example.
say I own a company where I have sales representatives
and I have customers
and an edge represents a sales relationship.
it makes sense for my sales reps to sell stuff to customers, right?
but it doesn't make sense for my sales reps to sell stuff to other sales reps
or customers to sell stuff to other customers
so every single edge is always between a sales rep and a customer.
and a node represents either a sales rep or a customer.
is there any good python dev who can help me out with one problem
if I were to represent that as a graph, it would be a bipartite graph, where the two groups are "sales rep" and "customer", and there are no edges between any of the "sales rep" nodes, or between any of the "customer" nodes
i am developing an app which main aim is to protect users privacy.
so i am having problem in creating a program.
like if someone send you a ip grabber link
who many of the user don't know whether it a safe url or a ip grabber
@brave oak oh i see. very thorough explanation. And there is calling self-loop regarding to bipartite graph
@brave oak oh i see. very thorough explanation. And there is calling self-loop
@maiden moon wait, what?
what do you mean by the last part
oh, okay
yes, there should be no self-loops in a bipartite graph
since a node is in its own group
so in that case there will be an program which will automatically gives the final url as ip grabber are bind with some real url. so the program will detect the real url and instead of that ip grabber link real url will come.
so can anyone help me out ?
so can anyone help me out ?
@tired arrow what's your problem
@brave oak well its is now clear for me. Graph can be described as 2d array right
i mean that ip grabber links are bind with a real url. so if anyone click on that ip grabber their ip address is captured. so i have a solution to solve this problem.
basically like auto correction of words we would be correcting the links.
for example there is a link which is shopify.co/watch/id=. so this is ip grabber link but this ip grabber link is bind with a normal url. basically when a person click on that ip grabber he will be redirect to a normal url and the person ip will be captured.
@brave oak well its is now clear for me. Graph can be described as 2d array right
@maiden moon yes, that is one way to represent a graph in memory
so if some one is typing www.shopify.co/ then it will automatically correct to the right link. the final link which will open.
as an "edge list", which is a 2D array where each row has 2 elements representing the IDs of the two nodes being connected
@tired arrow no, I mean, what do you want someone to help you with?
as an "edge list", which is a 2D array where each row has 2 elements representing the IDs of the two nodes being connected
@brave oak you can also model this 2D array as a Pythonlistoflists
and finally, going back to your original question: there are certain algorithms that can operate on an edge list to tell you if it represents a bipartite graph or not.
for that, I suggest Google or Wikipedia.
i want some one to tell me which python package will help me to create such program.
there is also an excellent Python graph library called networkx which you can look at
but I would strongly suggest you familiarise yourself with the basics of graph algorithms
before using the library @maiden moon
i want some one to tell me which python package will help me to create such program.
@tired arrow it's not that simple.
yeah i know
I mean
but my app main aim is security of the user.
it's really not that simple
that's not relevant
how noble your goals are doesn't affect how complex a project it is
okay, actually it's not that complex either TBH
but it depends on how you want to implement this
it sounds like you want it to be a browser addon
no
@brave oak does this mean 1 and 2 are connected and 3,3 are connected?
[[1,2],
[3,3]]
it will be implement in the app only which is messaging app.
if some is type message then in that message it will auto correct that ip grabber link to the normal url.
@brave oak
but it has 3 nodes, 3,3 is kind of a self loop ???
it is still not clear that how can i validate it is a valid edge ?
why do you think a self loop is not valid?
for that case, 2,2 is a valid edge too right?
yes, of course
we must distinguish between the graph itself and the business concept we intend it to represent
like the below link is a ip grabber but don't open it
there is nothing wrong with a graph having self loops
that being said, 2 it self alone node that is a valid too ???
but if your graph represents, say, Facebook, it doesn't make sense for there to be a self loop, right?
because you can't be friends with yourself
that being said, 2 it self alone node that is a valid too ???
@maiden moon no, that would not be valid
@tired arrow We're not going to let you post that ip grabber link
an edge must always be between two nodes
oh discord had done a good job to solve ip grabber problem.
it's just that those two nodes can be the same node
@torpid crown i was just saying that how ip grabber can captured your ip
so like [2, 2] is an edge from node 2 to node 2 (valid)
i am ethical person.
[2] is an edge from node 2 to nothing (invalid)
Just dont post the link again.
ah, so i have to check 2d array has more than 1 element?
well
so any idea how to create such programs
I think most algorithms assume that your edge list is already validly formatted
anyway @maiden moon I need to do stuff but I hope I've given you an idea of how to start
good luck!
@brave oak so, as for valid input, i just have to check input is making a valid connection?
@brave oak oh alright, thank you so much. It is a huge help.
@tired arrow so if I'm understanding this correctly, you're trying to detect IP grabbers?
yes
i am developing a secure messaging and social media platform app
which will not do data mining
like facebook
Alright. Us moderators get pinged every time a IP grabber is posted, just so you know.
but then that whole message is remove.
Hi I am a new python coder I only know the basics can someone teach me some advanced ??
π₯Ί
im new too
@iron sierra hit the docs , figure out why you want to learn python explore lib that match your interest , learn Data structures and algorithms
Yeah, you can't just say "Hey, please, teach me".
Especially not in a topical channel; did you read the server's rules ?
Rule 7
Keep discussions relevant to channel topics and guidelines.
Please allow me to reformulate Rocky's question
help
After learning the basics, what do you recommend to someone who does not have a cs degree. What do they teach at uni that you don't learn from the docs/googling?
Does someone have a cs book recommendation?
Look up Operating Systems in Three Easy Pieces. They have free PDFs of the chapters and while the example code is in C, the concepts are immensely helpful for understanding computer science.
One of the best books Iβve read regarding computer science as a topic and I recommend it to anyone. Helps you look at a lot of topics in a new way, including but not limited to pointers, arrays, abstract data types, threading/multi threading/concurrency/parallelism.
After learning the basics, what do you recommend to someone who does not have a cs degree. What do they teach at uni that you don't learn from the docs/googling?
@night grove nothing much, really.
it might just be more conveniently packaged
IMO
well, low-level stuff might be more accessible in an academic context
So Im interested in making websites and I have already learned css and html do any of you recommend me learning python next or no
LOOOOL
@fading juniper tf u mean LOOOOOL
oh i wasn't talking to you, sorry if that was rude. Learn python! it's great for most applications! 
ok thank you so much
@fading juniper Is python only for web apps?
Usually you would us JS for webapps (front end) Python is mainly for backend, but no, it's not only for webapps, it has several different uses
@main wyvern if your goal is to build websites then youβll have a hard time without knowing JavaScript
You need it if you want an interactive UI
There might be some python bindings for webassembly now which lets you write ui code? Not sure. But in any case pretty much all learning materials for websites will be in JavaScript
Python is nice for the backend of website, i.e. it it a great replacement for PHP, thanks to Django
@oblique coyote please do not do that you degenerate
@gritty python what makes you think this is okay.
!tempban @gritty python 2w spamming some bullshit drama message calling another member a degenerate in tons of topical channels.
:ok_hand: applied ban to @gritty python until 2020-09-10 12:32 (13 days and 23 hours).
I don't know if this is the right place
but, I'm trying to draw a line on an image in python, any ideas on how to do that?
are you on windows?
if drawing the line is the end goal you could jsut use imagemagick
Nope, it's not just the end goal. Only a small piece of a larger project
I'm trying to draw a line given two (x,y) coordinates on a fresh 2D image
using python
and ultimately export/save the image to some folder
turtle then
I can suggest pillow for drawing on images
but turtle works if it's a fresh canvas
ye, either is probably fine, depending on what else it needs to do
Pillow is pretty much the standard lib
I was just wondering
other than PIL
What's the most efficient way of drawing a line? Since I'll be using this to draw a curve
by connecting hundrends or thousands of points with small lines
Is the fastest way the pillow way?
the fastest way would probably be to do this in Cairo or sth in C/rust/nim
but for now, I would just try pillow and see if it is acceptably performant
Good idea
I'm not sure I can move the whole drawing logic to C, because honestly, I don't think I can make it work for now
You can translate a PIL image to a numpy array, and use fancy indexing/etc to get a good near-c speedup
doing drawing with np indexing sounds painful
Honestly I was thinking for a perfect curve, good point ><
julia may be nice for this actually
I've done some numpy image stuff, but never by individually plotting lines
I might recommend something with a canvas like pygame or kivy or whatever else is out there and then you can convert the canvas texture to a numpy array or save directly to some image format
that way you can use simple drawing functions without reinventing the wheel so-to-speak, though having a numpy drawing library might be fun to make
pillow does have drawing functions
that's convenient
You can translate a PIL image to a numpy array, and use fancy indexing/etc to get a good near-c speedup
@pallid coral could you give an example of the fancy indexing thing?
Or a link to a place which explains doing that, cuz I can't find any
See "advanced indexing"
you can index a square, compute a circle matrix and apply it, etc
one thing to consider is you can make a square, use a rotation matrix multiplied with it, use that rotation matrix with > 0 to get a mask, use the mask to multiply it appropriately and use that for close to pixel-perfect roatations
also check out upbge and using curves / splines / meshes to draw stuff
it also has a GPU module
Guys tears of joy emoji is represented with this 11111011000000010, this i think is represented with continuous bits... why is it not represented by multiple byte
Guys tears of joy emoji is represented with this 11111011000000010, this i think is represented with continuous bits... why is it not represented by multiple byte
@gusty bay why do you say that?
tears of joy emoji is represented with this 11111011000000010
this part
i just confused is it necassary that bits are always stored as byte?
hm.
the simple answer to your question is "yes"...but I would be more interested in understanding what exactly you're confused about
oke so this is what is in my head
because a byte is a group of bits (most often 8)
so asking "are bits always stored as bytes" is kind of a strange question
1 bit is on or off, and 1 byte is 8 bits...so to represent the letter 'A' we can need an input of 65 which is 010000001 (this is represented within the limit of a byte). but if i were to represent an emoji i would need to have an input of 128514, and the binary for this is 11111011000000010 shouldn't the bits be divided into bytes bcuz they are continuous with growing power (2^0, 2^1 ...2^10...) .... In byte we only have 8 bits and the maximum power would be 2^7... so wouldn't the emoji be represented with series of byte with different values equal to or less that 128 then we could add them to form 128514
._.
HM.
okay
so the thing is
characters are not just numbers
characters have encoding
the most common of which is UTF-8
so UTF is continous bits?
so wouldn't the emoji be represented with series of byte with different values equal to or less that 128
but even then this would not be true
it would (basically) be more like...(byte_1 * 128 ^ 0) + (byte_2 * 128 ^ 1) + ...
just like if you look @ it on a bit level it's (bit_1 * 2 ^ 0) + (bit_2 * 2 ^ 1) + ...
pty sure encoding is "a list that has all the characters and their numerical value"
@fiery cosmos not just that...?
or rather, that would not cover variable-width encodings, which UTF-8 is
@brave oak thankuuuuuuu
How much time did you take to finish MIT 6.006?
about a month or so
Even i started 5 days back(MIT6.006)...I am targeting 1 lecture and recitation per day..Hope I'll continue without any distractions
can somone explain this to me
#include <stdio.h>
void swap(int *x , int *y)
{
int *temp;
temp = x;
x = y;
y = temp;
}
int main()
{
int x = 5;
int y = 10;
printf("x = %d\ny = %d\n", x, y);
swap(&x, &y);
printf("x = %d\ny = %d\n", x, y);
return 0;
}```
why doesn't this switch the values?
is it cause the addresses are call by value as well?
why does it work if I dereference them
@fiery cosmos because you want to swap the values the pointers are referencing, and not the pointers themselves.
That said, this is a Python server, so I'm not sure why you're posting it here
this is a computer science channel
as it relates to python
π
Can someone please tell me what this line of code does? :return "({}x {} {})".format(commonfactor(d), '-', abs(n))
each {} refers to an argument of .format()
it can also be written f"({commonfactor(d),}x - {abs(n)})"
stray comma. It's just f"({commonfactor(d)}x - {abs(n)})"
in multiprocessing can i do something like this
writer = mp.Process(target=write_to_db,args=(q,))
with mp.Pool(initializer=init,initargs=(q,)) as pool:
for i in pool.imap_unordered(append_to_queue,iter):
writer.run()
writer.join()
writer.close()
i'm just running into too many locking issues with sqlite3
is this better for the databases channel?
the locking issues are why i am trying to make a dedicated writer process which will have exclusive access to the database
@grizzled cargo there isn't really a topical channel that encompasses parallelization. If you're still having trouble with this issue you might open a help session.
actually it looks like it's in the scope of #async-and-concurrency
i've been doing some runtime analysis and wanted to graph how bad the algorithm is if you dont optimize it.
actually had to switch to a log scale lol
but its pretty much perfectly "linear" in log scale then π
haha
if you just dont add "in log scale" it looks like O(n)
Is that done with perfplot? I love it too, such a nice library.
what's the x axis?
I assume it's a plot of 10**n
Hi everyoneβ Iβm fairly new to discord so apologies if this is the wrong channel. I have a question regarding time series analysis/handling missing data in a df. Is this the proper channel to ask that type of question?
@dry obsidian hi, the folks at #data-science-and-ml might have more experience with it, or you could open your own help channel #βο½how-to-get-help
can anyone help me?
my question is write a code that prints yur name and your birthday as separate strings
im new to python
@tranquil hamlet that's not really comp sci, that's basics. see #βο½how-to-get-help
no lol its for comp sci class in school hehe
that is general/basic python and belongs in one of the regular help channels
ok then
@vocal gorge no, matplotlib, whats perfplot? sounds cool
@agile sundial x asis is just N, y axis is the output size
its kinda like a function f(n) -> List[...] where y elements are returned
def pinv_method(A, bx, by, bz):
Af = np.linalg.pinv(A) # pseudoinvese A
x = Af @ bx
y = Af @ by
z = Af @ bz
return np.vstack((x, y, z)).T
def linalg_solve(a, bx, by, bz):
x = np.linalg.solve(np.dot(a.T, a), np.dot(a.T, bx))
y = np.linalg.solve(np.dot(a.T, a), np.dot(a.T, by))
z = np.linalg.solve(np.dot(a.T, a), np.dot(a.T, bz))
return np.vstack((x, y, z)).T
def basic(a, bx, by, bz):
Af = np.dot(np.linalg.inv(np.dot(a.T,a)),a.T)
x = Af @ bx
y = Af @ by
z = Af @ bz
return np.vstack((x, y, z)).T
def pinv_no_factorization(A, bx, by, bz):
x = A @ bx
y = A @ by
z = A @ bz
return np.vstack((x, y, z)).T
def lsqr_method(A, bx, by, bz):
x = lsqr(A, bx)[:1]
y = lsqr(A, by)[:1]
z = lsqr(A, bz)[:1]
return np.vstack((x, y, z)).T
@flat sorrel @vocal gorge
for 1.5k
times are good now but result are not very smooth
i mean it is what it is in the paper
i think its because we minimize the sum of point to neighbors distances, not the distances itself per point
im not sure if it would still have least squares solution in that case
so now you're basically setting the target distance to zero?
yes
i mean, thats what they do in the paper, and I switched from my initial task since least_squares failed with speed and i couldnt come up with Ax=b solution for it
I see
Just a random thought, have you considered using a physics-based iterative solution?
with connected points attracting/repelling each other based on whether they are further away or closer than the target distance
i've tried iterative solution, but i wouldn't say it was physics-based - i just was calculating the neighbors average on one iteration, putting points in there on the next, checking edge lengths and making alterations on further iterations etc. several hundred iterations per point to get some fair results - it wasnt that fast
and it wasn't, lets say, robust )
I see
https://bellard.org/pi/
at the top it says they computed 2700 billion digits of pi with a regular computer
but it also says the best algorithm for finding n digits of pi is O(n^2)
how is this possible
shouldn't n >= 10^4 be infeasible
@winged moon
https://en.wikipedia.org/wiki/GaussβLegendre_algorithm, which seems to still be the most useful:
The algorithm has quadratic convergence, which essentially means that the number of correct digits doubles with each iteration of the algorithm.
so that's very much not O(n^2)
oh I incorrectly assumed "quadratic convergence" meant O(n^2)
when in reality it's O(sqrt(n))
the way they say it, it's actually more
if that's not a mistake and the number of digits doubles every iteration, it's O(log(n)) iterations.
though maybe the time per iteration increases too and that works out to O(sqrt(n)) time.
Basically trying to figure out how to understand and do this can anyone help me out I sadly do not know how to figure it out
I don't want the answer I do want to figure this out but I've been searching for 30-40 mins and have gotten no closer to figuring out how to interpret any of this
Ah.
It just wants you to apply the very simple idea: when writing the asymptotic complexity, you leave only the fastest-increasing term, with no constant.
So O(2*n^2 + 2n + 1) is O(2*n^2) (drop all other terms) which is O(n^2) (constant doesn't matter).
O(3n^2 + 2^n) is O(2^n).
And so on.
So like say 2n^3 + 3n^2 would be like 0(n^3)?
yup
Thnx that's very helpful
for big enough n, it scales like n^3 - that's what the O-notation means.
Ok got it. So basically it doesn't really care about the equation after the initial part?
It's all about the dominant term, no matter where it is in the runtime formula.
Uhh, no, 3n^2 + 2n^3 is still O(n^3).
Ok
0.001n^2 + 10000000n is tripping me up then would that be like 0(n^2 n) or something?
yea you could have like
O(n^3 + 1000000000000000000000000000000000000000000000000000000n^2)
and it would be the same as
O(n^3)
(but in practice this is probably false lol)
0.001n^2 + 10000000n is tripping me up then would that be like 0(n^2 n) or something?
@sudden ember it might seem counter intuitive, but if you have0.001n^2or10000000n, 001 and 100... are still constants
but by definition it is true
and there's some value of n for which the first one is going to be much larger than the other.
@sudden ember Basically, the O-notation describes the behavior as n goes to infinity. Here's a formal proof that
n^3 + 10**100 * n^2 is O(n^3):
f(n) = n^3 + 10**100 * n^2
Let us divide f(n) by n^3. We get:
f(n)/(n^3) = 1 + 10**100 /n
When n goes to infinity, this goes to 1, a nonzero constant. Therefore, by definition, f(n) is O(n^3)
f(n) is O(<something>(n)) means (f/<something>) (n) goes to a nonzero constant when n goes to infinity.
Crucially, big O notation doesn't tell you anything at all about relative performance of two algorithms except when N grows arbitrarily large. One algorithm being O(N) and another being O(1) doesn't tell you that the O(1) one is always faster, only that given enough items eventually some tipping point will become reached where it will become faster.
Inserting into a hash table - O(1) - will not always be faster than inserting into a dynamic array - O(N) - because when N is small, the constants can dominate the runtime. For a contrived example, imagine that your hash function takes a consistent 1 second to hash one item. That's constant, and doesn't vary based on the number of items previously inserted, so your hash table insertion is still O(1), but it isn't fast, so plenty of O(N) algorithms will be able to beat it for most values of N.
Hey guys anyone here that studies at a UK university
@lean dome something I thought of when learning hash tables is that even though all the operations are best case O(1) for n entries, that doesn't tell you anything about the hash algorithm
So you could probably get some bad performance in python if you're using long tuples as keys up to a certain number of dict values.
even though all the operations are best case O(1) for n entries
@oblique panther not just best case, average case, and amortized as well
Right
Hi , I want to ask something about taking offer , I am high school student and I want to learn deep learning. before start that I work on image processing with OpenCV. now , I can't improve here because I purchase a course but it's insufficient. after I look another source lot of books , essays , videos but all of these blurred in my mind so I don't know how can I start that I watched Neural Networks from scratch series in these days. now what I should to do ? when I click get started button exist in Keras main site after I dont know which options suitable for me, so what I should ???
I write that here I don't know is it true place
#data-science-and-ml, generally.
You might to take one of the many coursera ML courses; they can be done for free in audit mode (can't take quizzes, but that's the only limitation). It sounds like you learned a lot of theory without any practice, so you need a course that guides you though an actual project.
should that start at ML
because when talk with who knows about that he says learn DL
personally, I loved this amazing introductory ML course: https://www.coursera.org/learn/machine-learning (also completely free)
And then take the ones you like from https://www.coursera.org/specializations/aml - the first one seems to be what you want.
because when talk with who knows about that he says learn DL
I mean, that's like saying "don't bother with arithmetics, learn calculus instead" π
Hi i am wondering if i can get the explanation to 100110111111 in hexidecimal
16 = 2**4 - a single digit of a hexadecimal number represents exactly as much information as 4 bits.
As a result, to convert binary to hexadecimal, split it into blocks of 4 digits(pad with zeros to the left if necessary, then convert each block.
so:
1001 1011 1111
9 B F
9BF
@rugged oasis
ok i was just confused because there were more than usual
10111010011 would be:
101 1101 0011 - length not divisible by 4, add a zero to the left
0101 1101 0011
5 D 3
5D3
ok, so could I ask in here where to find a good tutorial for using python to make a basic AI?
Trying to get it to learn a number game by playing against a player...
how can i check interval scheduling job is compatible ?
how is life like when you do cs?
Can you suggest another way of having the functionality the class searchNodeMaker(dict) provides here https://py3.codeskulptor.org/#user305_MIkOQUGRta9iO5Z_1.py ? I am trying to write that code into C++ and I don't know how to convert that.
ok, so could I ask in here where to find a good tutorial for using python to make a basic AI?
Trying to get it to learn a number game by playing against a player...
@lament portal Read on from here:
https://discordapp.com/channels/267624335836053506/303906556754395136/750077678996160643
In short, that'd require learning quite a lot of ML. A basic value-learning tic-tac-toe AI is also discussed in the first chapters of this nice book: http://www.incompleteideas.net/book/the-book-2nd.html (downloadable for free from the official site)
thank you!
I also waas told to look at Convulational Neural Networks, but I will look at this also!
that can be somewhat relevant, but game AIs pretty much require reinforcement learning, which is quite different from both supervised and unsupervised.
(In supervised, you give examples of the right things to do and the network generalizes from them. In RL, you don't give any examples at all, but you give rewards/punishments for actions - so the network needs to experiment and learn what gets it the highest rewards, and also balance exploration and exploitation).
Hey, I want to become an embedded developer. Does anyone know someone who's an embedded developer that I can talk to?
I want to develop a roadmap so that I can know what to learn.
what is the maximum number of addresses that can be referenced? (1 byte store memory address)
anyone know^^
??
on 32bit, 4GB, on 64bit, its complicated
I mean architectures with 32bit long machine words have 4GB of address space, and architectures with 64bit long machine words have more, but how much more depends. Generally 48bit addresses, so 281TB of address space.
@mint jewel i am talking about 8 bit
there are no 8bit architectures novadays
Lol

depends how many bits the byte has. π€·
for or_dist_xor
would be ((x xor y) or z) == ((x or z) xor ( y or z)) ?
@mint jewel 8 bits
https://www.youtube.com/playlist?list=PLowKtXNTBypGqImE405J2565dvjafglHU
Yup, he's great
Not even in university do you learn all this stuff and apply them.Meanwhile this man without asking for any fee gives it for free.
LEGEND
Tbh, I want to study microelectronics because of him
There is also a post in /r/electronics
Searching by top
You can find it
Its a 16 mb computer
Inspired by bens project
And the poster has built his own semi-terminal
Its pretty cool
@north zealot its an interesting field but probably one of the most difficult ones.
If some field cuts ties with electrical or mechanical engineering you know its difficult.
Also you must have calc 1 and 2 , algebra/linear, pysichs(electricity) hammered in since high school.
matrix 99% sparse but sparse inversion is 3x times slower than regular numpy inv
a = sc.sparse.csc_matrix(np.dot(a0.T,a0))
b = sc.sparse.linalg.inv(a)
any suggestions to check smth?
~19000 non-zero elements in 2250000 matrix
which means less than 1% density
on top of that it is square and symmetrical... dafuq
This computes the sparse inverse of A. If the inverse of A is expected to be non-sparse, it will likely be faster to convert A to dense and use scipy.linalg.inv.
mkay... )
i assume the part where numpy finds out what elements arent sprase is something like O(n) where as just a array operation is closer to ~O(1) because of vectorization
is this 24ms?
i cant believe my eyes
ok, so sparse inversion was not suitable in my case because result was a dense matrix
but sparse cholesky performs really well
btw im surprised i was able to replace inversion with cholesky without any changes to my equation
or wait...
damn im so stupid
ok, so how do I get inverse of A, if i've got cholesky of A which is factorized upper triangular matrix i think.... right?
well , in case of scipy its upper by default i think
ok, so here i found the equation to compute A inversed through cholesky decomposition
I found out that scipy.linalg.lapack.dtrtri is very fast with inverting triangular matrices
but...
def basic(a, bx, by, bz):
X = np.dot(a.T,a)
# working equation Af = np.dot(np.linalg.inv(X),a.T)
# calculating inverse of X by finding cholesky decomposition
# upper triangular matrix U, invert it, and then
# X_inv = U_inv @ U_int.T
U = sc.linalg.cholesky(X)
Ui = sc.linalg.lapack.dtrtri(U) # triangular inverse, VERY FAST
Ui = np.asarray(Ui) # convert to array since lapack returns tuple or smth
Xi= np.dot(Ui,Ui.T)
Af = np.dot(Xi,a.T)
x = Af @ bx
y = Af @ by
z = Af @ bz
return np.vstack((x, y, z)).T
this ^ doesnt work as expected, just plain wrong results
Af = np.dot(np.linalg.inv(X),a.T) - this line gives correct Af
replacing lapack inversion with numpy np.linalg.inv(U) works fine
so the problem is lapak output...
ok, I think lapak tuple has a strange format
ok, it works
thanks everyone )
@fresh mulch
- this isn't really a computer science question, see #βο½how-to-get-help
- please post your code as text and not a screenshot when possible, a screenshot can be hard for some people to read
@fresh mulch indent while loop and its body
when you try
to test for a happy number by squaring and adding the digits
does the loop for non-happy numbers always go back to the beginning?
huh?
@icy swallow what's a happy number?
don't you just keep looping until it's 1?
What?
Have my controlled assessment for making a game this year donβt have many details yet on it but any one who has already done it yr10 uk help would be greatly appreciated
def int2DArrayToString(list2D):
return ', '.join(str(item) for innerlist in list2D for item in innerlist)
I pass a 2D list to this function but after each row of the list how can I add a new line character to it? Currently the output looks like this if I pass a random 2D list to it.
2643072647183320516, 6188249542919180808, 4366718118959125391, 3988393958240311701, 7792024028097894202, 6521062128143204340
But I want it to be formatted like this
2643072647183320516, 6188249542919180808, 4366718118959125391
3988393958240311701, 7792024028097894202, 6521062128143204340
also sorry if this is the wrong text channel to post in for this question
join on the inner list, you don't need the second loop
It's a bit of a weird channel choice, yeah. A help channel would probably be better.
What you want, though, is something like:
def int2DArrayToString(list2D):
return '\n'.join(map(", ".join,(map(str,innerlist) for innerlist in list2D)))
hmm, can do a nested map...
ok i see what you did thank you for the help
https://gist.github.com/markus-beuckelmann/8bc25531b11158431a5b09a45abd6276
guys can you please run this BLAS test on your machines and tell me the results and whats your CPU
A short Python script to benchmark NumPy and show your BLAS setup - numpy-benchmark.py
Dotted two 4096x4096 matrices in 1.18 s.
Dotted two vectors of length 524288 in 0.18 ms.
SVD of a 2048x1024 matrix in 0.86 s.
Cholesky decomposition of a 2048x2048 matrix in 0.15 s.
Eigendecomposition of a 2048x2048 matrix in 8.53 s.
This was obtained using the following Numpy configuration:
blas_mkl_info:
NOT AVAILABLE
blis_info:
NOT AVAILABLE
openblas_info:
library_dirs = ['C:\\projects\\numpy-wheels\\numpy\\build\\openblas_info']
libraries = ['openblas_info']
language = f77
define_macros = [('HAVE_CBLAS', None)]
blas_opt_info:
library_dirs = ['C:\\projects\\numpy-wheels\\numpy\\build\\openblas_info']
libraries = ['openblas_info']
language = f77
define_macros = [('HAVE_CBLAS', None)]
lapack_mkl_info:
NOT AVAILABLE
openblas_lapack_info:
library_dirs = ['C:\\projects\\numpy-wheels\\numpy\\build\\openblas_lapack_info']
libraries = ['openblas_lapack_info']
language = f77
define_macros = [('HAVE_CBLAS', None)]
lapack_opt_info:
library_dirs = ['C:\\projects\\numpy-wheels\\numpy\\build\\openblas_lapack_info']
libraries = ['openblas_lapack_info']
language = f77
define_macros = [('HAVE_CBLAS', None)]
I have a i5-8500
yeah, taking your results and results i've seen on the internet, seems like my mkl BLAS works fine, no need to manually compile numpy with OpenBLAS or ATLAS or some shit to speed it up
but it's strange how people in the paper solve two linear systems on Pentium4 10x faster than I do single Matrix-Vector multiplication with BLAS
how the f...
and matrix multiplication in numpy performs the same as a good c++ code
@viral zenith numpy is implemented in C
it uses BLAS library
that maybe C too,
but it doesnt matter
i mean its the fastest you can get
Cough cough gpu cough cough
yeah, i was talking about CPU since on my original question I was comparing it to CPU method from the paper
I assume this is somewhere in this channel, but what's a simple way to run a script (or a certain loop) on the GPU?
I've looked at some options but I dunno if theres a simpler way
@autumn blaze that question isn't on topic for this channel, but you'll want to look into Cuda.
Oh okay sorry
that's only for nvidia gpus tho
I'm not sure there's really a room for gpu computing in the server, it's generally within some other context
Also if you're directly using cuda it's no longer relevant to python either (until you eventually possibly bind it to python)
Yeah ok
I'm doing some machine learning in python and wanted to see if I could make it any faster
In that case you can go in #data-science-and-ml
You also won't need to use cuda directly, machine learning (deep learning really) libraries will use it under the hood
Check out "numba"
If you're not using a library, don't worry about the performances, because it will be terrible either way
Hah yeah probably
It can run in the gpu
Deal
Hi I'm trying to code a RC robot and was wondering if i could get that help here or is there a better channel that i could go to? I'm beginning to code so i don't exactly know the basics either.
hm, you can always ask, if its out of place someone will tell you where to go
Is there a better channel that i could go to or is this one fine?
