#algos-and-data-structs
1 messages ยท Page 142 of 1
What do you mean?
whats simulation?
i.e. the precision depends on the dt here
simulation as in you repeatedly compute what the situation looks like a small time step into the future
this would be the most basic thing, the thing people would try instinctively: https://en.wikipedia.org/wiki/Euler_method
I guess my code is technically that, and so is Katakana's code (but with dt=1)
oh okay
What's the equivalent of zip(*args)?
The context is, I'd like to find a way to get a list of the columns of a sudoku board. using zip(rows) will give me all the columns AFAIK, but I'm not sure if that's considered cheating or not. I wonder if there's a better way ๐
the core part of the solution I would have expected if I asked this problem to someone is
t = 0
while pos1 < goal and pos2 < goal:
pos1 += dt*vel1
pos2 += dt*vel2
t += dt
at the end we have final positions and the final time
Yes
for part 2 you have different logic for one of the people
Yeah
if I needed the columns I would do the zip, for sure
its just a logic problem
does it take 20 mins for to charge
or hours
Minutes
for every hour in v2timetaken add 0.4
try to code that
i'll do it this side too
K
do not hardcode the numbers though, that are supposed to be given as inputs
Thats what this problem got me too
no maths here would surely just means don't use the closed form equation
but simulate instead
simulation will of course involve some math
Got it! Thanks a lot ๐
No math involved
log
but you are adding and multiplying numbers in your code ๐ฑ
Oops my bad
right
What if I was put in a situation where I cannot use zip? Would I have to use a naive solution like looping through the rows of a sudoku board, then getting all the 0 indexes, appending them to a new row, then moving to all the row[1]?
That would be n^2 huh
input()*2/100 is not a equation tho
any solution is at least O(nยฒ), because there are O(nยฒ) elements
why*2/10?
then v2timetaken += (v2timetaken*0.4)
0.4?
sincr minues to charge is 20
it's not in general, it's an input you get
ik but assuming the input you get is 20
20*2/100
= 0.4
you really can't assume a constant velocity here
they will run for a bit and then stay still while charging
this is one way of implementing the actual logic, only advance if we are in the operation phase
t = 0
while pos1 < goal and pos2 < goal:
t_cycle = math.fmod(t, t_o+t_c)
if t_cycle <= t_o:
pos1 += dt*vel1
pos2 += dt*vel2
t += dtโ
that's all the changes that would be needed for my solution
fwiw, math.fmod(x, m) takes x and removes as many multiples of m from it as it can (it's the float equivalent of modulo for integers)
Never learned math.fmod in my class so I am unable to use this function
the full operation-charge cycle takes t_o+t_c time, and we can only move in the first t_o time
(well f**k your teacher then...)
you can implement if manually, but it's dumb to have to do so
I f***king agree
t = 0
t_cycle = 0
while pos1 < goal and pos2 < goal:
if t-cycle <= t_o:
pos1 += dt*vel1
pos2 += dt*vel2
t += dtโ
t_cycle += dt
if t_cycle >= t_o + t_c:
t_cycle -= t_o + t_c
this would be doing it manually
(a cute way of implementing this whole thing would be to use generator functions, but let me guess those aren't allowed either)
(god I hate seeing those 1s instead of a dt)
also, there is no point in tracking both times, they are the same
but why? you can't assume constant velocity like you were doing earlier
it's wrong and I want to spare the misery of implementing the wrong thing in vain...
Make sense
e.g. pick t_o = 1, t_c=999 and pick the distance that is 1*velocity
the actual solution is 1 minute
the solution with the constant velocity thing is 1000 minutes
it's just...wrong
Ima head to bed because it's 2 where I am at and I have school tomorrow
i'm back
K
Did u do it?
smh i still dont get why math shouldnt be involved in this problem
his teacher is prolly mathematically challenged
does the adjacency list representation have a faster Big O time complexity than the adjacency matrix representation when both are applied with Dijkstra's Algorithm??
adjacency list doesn't give better time complexity, but it's a lot better for space complexity
adjacency matrix is really wasteful unless you have almost a fully connected graph
what would be their Big-O time complexities?
time complexity for what exactly?
both adjacency list and adjacency matrix when they're applied with Dijkstra's Algorithm
which of the two representations you use doesn't impact the time complexity of Dijkstra
I guess technically is could be slower for adjacency matrix because you need to scan more elements to find neighbors 
https://www.geeksforgeeks.org/dijkstras-algorithm-for-adjacency-list-representation-greedy-algo-8/#:~:text=We have discussed Dijkstra's algorithm,O(V^2).&text=With adjacency list representation%2C all,%2BE)%20time%20using%20BFS.
does this explain it well or something
if you want neighbors, adjacency list is just a nicer representation to work with
class node:
def init(self,value= None):
self.value = value
self.left_child = None
self.right_child = None
class BST:
def init(self):
self.root = None
def insert(self,value):
if self.root == None:
self.root = node(value)
else:
self._insert(value,self.root)
def _insert(self,value,cur_node):
#From root check whether to go right or left
if value < cur_node.value:
#if there is no value on the left child node inset value here
if cur_node.left_child == None:
cur_node.left_child = node(value)
#else call recursive function to continue as if left node is root
else:
self._insert(value,cur_node.left_child)
#From root check whether to go right or left
elif value > cur_node.value:
#if there is no value on the right child node inset value here
if cur_node.right_child == None:
cur_node.right_child = node(value)
#else call recursive function to continue as if left node is root
else:
self.insert(value,cur_node.right_child)
else:
print('Value already in tree')
def print_tree(self):
if self.root != None:
self.print_tree(self>root)
def _print_tree(self,cur_node):
if cur_node != None:
self._print_tree(cur_node.left_child)
print('%d'% cur_node.value)
self._print_tree(cur_node.right_child)
def fill_tree(tree,num_elems = 100,max_int = 1000):
from random import randint
for k in range(num_elems):
cur_elem = randint(0,max_int)
tree.insert(cur_elem)
return tree
tree = BST()
tree = fill_tree(tree)
tree.print_tree
is there a scenario where adjacency matrix doesnt have a slower time complexity over adjacency list?
the one thing adjacency matrix is useful for is if you want to answer "is a connected to b?" quickly, which is kinda rare
when applied with dijkstra's algorithm that is
I would say just use adjacency list as the default graph representation unless you have good reason to do otherwise
I've never seen a use for that kind of BST 
balanced binary search trees (BBST) have good uses though
how do i develop a directed acyclic graph for a factorial?
i got it on a youtube video
i am gonna code on my own since understand theory behind
in a fully connected undirected graph, which has a higher space complexity,
adjacency matrix or adjacency list representation
it's the same
is there a case where a. matrix has higher space complexity than a. list considering the same fully connected undirected graph?
no
so the space complexity between the two are always the same under that kind of graph then?
yes, think about the two data structures
is there a scenario where backtracking is better over complete search in terms of worst case time complexity
considering they deal the same problem
yes, when backtracking you can use the previous states to narrow down the states you have to search
is this always the case or can complete search be better in terms of worst case time complexity under other conditions?
no, complete search is almost always worse than everything else
why almost
i say almost because there's probably a case i didn't think of or don't know about
if I have
arr = [["name1", number1],["name2", number2], "name3", number3]]
and i want to sort the array with respect to the numbers, how can i do that?
!d list.sort
sort(*, key=None, reverse=False)```
This method sorts the list in place, using only `<` comparisons between items. Exceptions are not suppressed - if any comparison operations fail, the entire sort operation will fail (and the list will likely be left in a partially modified state).
[`sort()`](https://docs.python.org/3/library/stdtypes.html#list.sort "list.sort") accepts two arguments that can only be passed by keyword ([keyword-only arguments](https://docs.python.org/3/glossary.html#keyword-only-parameter)):
*key* specifies a function of one argument that is used to extract a comparison key from each list element (for example, `key=str.lower`). The key corresponding to each item in the list is calculated once and then used for the entire sorting process. The default value of `None` means that list items are sorted directly without calculating a separate key value.
the key function mentioned here
a[1], but yeah
filter(function, iterable)```
Construct an iterator from those elements of *iterable* for which *function* returns true. *iterable* may be either a sequence, a container which supports iteration, or an iterator. If *function* is `None`, the identity function is assumed, that is, all elements of *iterable* that are false are removed.
Note that `filter(function, iterable)` is equivalent to the generator expression `(item for item in iterable if function(item))` if function is not `None` and `(item for item in iterable if item)` if function is `None`.
See [`itertools.filterfalse()`](https://docs.python.org/3/library/itertools.html#itertools.filterfalse "itertools.filterfalse") for the complementary function that returns elements of *iterable* for which *function* returns false.
thank you guys for your help
i got the solution to my problem
@slim crest
@haughty mountain
what was it
its stupid but i got it this morning
its okay
okay thats cool
thx for the help
comeback if you have any more problems
and is kuroko's basketball your fav anime?
yeah there is still 1 more part for this problem
i will see if i have any more problems
Jujutsu Kaisen takes .#1
okay
Have you tried @slim crest?
no not yet
df_out = dfs
can some please help
help with what
o notations
yes, but what specifically in this problem do you need help with
nevermind I'll ask my mom in the morning
however
heres my stab at a code challenge
how can I make my program more efficient
hm
@high pewter Don't ask if anyone is available, just ask your question.
If people see a question, they will be more likely to help.
the question was stated earlier
the code I sketched for part2 is easily adaptable to this task as well, this is just the same logic but for both simulations
K thank you
Yeah it's the same logic
I tried to use the same thing
But Mr.Veera position does not change
the thing you ended up writing does not generalize as easily I think
K
like, my code change is just
t = 0
while pos1 < goal and pos2 < goal:
t_cycle = math.fmod(t, t_o+t_c)
if t_cycle <= t_o:
pos1 += dt*vel1
pos2 += dt*vel2
t += dtโโ
```to
```py
t = 0
while pos1 < goal and pos2 < goal:
t_cycle1 = math.fmod(t, t_o+t_c)
if t_cycle1 <= t_o:
pos1 += dt*vel1
t_cycle2 = math.fmod(t, t_b+t_r)
if t_cycle2 <= t_b:
pos2 += dt*vel2
t += dtโโ
dt is the time step, I guess you use 1 everywhere
re: fmod
just because I don't like having it hardcoded as 1, it's also a thing that you are likely to want to change for the sake of precision
maybe some examples help with what fmod does
fmod(1.0, 2.0) == 1.0
fmod(1.5, 2.0) == 1.5
fmod(2.0, 2.0) == 0.0
fmod(2.5, 2.0) == 0.5
fmod(3.0, 2.0) == 1.0
fmod(3.5, 2.0) == 1.5
fmod(4.0, 2.0) == 0.0
...
i se
comebine your function with a positional argument? 1 function to process both?
wish i could help you katakana!
is anyone know of a good cheat sheet for the basic python and data structure??
*guess google is my best friend lol.. for anyone that might be interested i found this:
https://www.pythoncheatsheet.org/
Heap is overrated
*angry dijkstra noises*
I made an algorithm that reports possible swaps in a bejeweled board along with their potential streak.
id like to see if any one has a conceptual idea of how they would do it or an implementation
so i can compare mine to yours
im very proud of my way but there might be another way
maybe give more context. Whats the problem and what are partitions.
Thank you @slim crest and @haughty mountain
partitions are breaking of numbers
i am officially done with the mathematical challenged teacher question
bro i lost my soul in these past 2 days
the problem was worth 30% of my mark
for example p(4) = 5
i am done
damn
i will for sure come bac if i have any more problems
but thank you
and have a great weekend
may god bless you all
1+1+2
amen ๐
well see thats alot easier to grasp than all that math in the beginning. Now somone may be able to help. Just need to put it all in one sentence and post it.
!e
for number in range(100,8):
print(number)
@autumn pendant :warning: Your eval job has completed with return code 0.
[No output]
!e
Hey guys!
Can you please suggest how to sharpen data structures and algorithms skills?
watch tutorials and solve problems like i am right now
what's the cooldown name in python?
!e
print("Hi"
o
!e
import Discord
from discord.ext import commands
client = commands.Bot="?"
@ember shore
async def ping(ctx):
await ctx.send("pong"
bot.run("123")
@clear vortex :x: Your eval job has completed with return code 1.
001 | File "<string>", line 6
002 | <@โ!545576944008298516>
003 | ^
004 | SyntaxError: invalid syntax
@clear vortex #bot-commands please dont spam here
i didnt spam-
Good morning to everyone, I'm working on a csv file and I would like to write another csv. In particular my csv is composed of persons and an associated measurements list ( person1|[m1,m2,m3....] person2|[m1,m2,m3...] ecc). I want obtain something like this: person1|m1|m2, person1|m2|m3, person1|m3|m4, person2|m1,m2|.... So I would loosen the list and write a row for each tuple. Any help? I hope I was clear
i try to explain better using pseudocode
FOR EACH ROW IN CSV
name= row[0]
surname=row[1]
list= row[2]
if list.size==1
write name,surname, list[0], null
else if list.size>1
for i=0, i<list.size-1, i++{
write name, surname, list[i], list[i+1]
}
so I want to read from a csv and write on another csv
You want each pairwise tuple?
I think itertools module might help you in breaking it up
perhaps the pairwise() function from it or product(), hope that helps... if I understood correctly
If anyone is interested on working with me with an expert-level hackerrank puzzle, send me a dm! I've been stuck on one for a while... i'm using python to solve it.
not dm, but why not link the problem here?
i have a question would it be possible to loop without looping i have an issue with automatisation and i just can't figure it out any help or idea would be more than welcome
would it be possible to loop without looping
what does this even mean?
my hash function for bejeweled swaps. only cares about combinations not permutations.
hash = is_horizontal ? min(swapee_index, swaper_index) : min(swapee_index, swaper_index) + (columns - 1) * rows
sorting a string is O(n log n) and then joining it back again via join is O(n).
So to sort a string and then join it, it would be O (n) + (n log n), but we would simplify it to O(n log n)?
and if we have to perform the same sequence on a list of words, then we would be looking at O(K N log N), where K would be the number of words in a list, and N would be the length of each word?
words = ["This", "is", "a", "test"]
Wouldn't it be O(nยฒ log n)
Or O((1 + log n) n)
How would it be O(n^2 log n)?
It wouldnt be n^2 because we need to have a distinction between the length of each word (N), and the number of words (K) is a list/array.
Does anyone know of a weighted graph generator? I know its a super niche usage case but I really dont wanna manually write out a directed graph
OH wow this is really cool. I wish there was an option to simply export the graph in like python dictionaries
Can somebody in here help me with the minimax algorithm? I make tic tac toe for a school project and struggle finding a way to implement this algorithm into my game so I can make an unbeatable ai. I would appreciate help alot.
.
recursion
Send the code you have already
wait
problem might be that it is mostly in german since its for a school project
but I can still send
and I tried multiple times but all tries didnt work
so should I just send you the code of my twolayerbot?
Pasting large amounts of code
If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.
Oof, sorry, forgot about this. I'll get back to you in 15 minutes i just have to hop on a quick meeting
it's ok
@soft cape is your problem coming up with the algorithm, or are you encountering some kind of error in your program
I just can't figure out how I should rewrite the bot function to not just look 1 move into the future but simulate every possible outcome
I watched several videos but none of this worked and couldn't figure it out
and in most of these Videos the Bot starts and in my program the player starts and not the bot
Alright, so I don't really understand the architecture of your program, but I'll help you out with hypotheticals ๐ is that good?
Can you point me to your minimax implementation if it exists already in your code?
it doesn't exist yet
but it should exist in the twolayerbot function
there already is a loop which predicts 1 move into the future
it should be the second for loop
Well minimax is composed of a set of components
These components are:
- function that defines the utility (preference) of a state
- function that defines how to transition from state to state
- function that defines the transitions for a particular state
- function that defines if a desired state has been found
- function that defines what transition is best for the current state
The easiest to implement right now is 4.
It seems you've implemented it already, right? In the first function in your source code @soft cape
yeah the first function tells if someone won
either the player or the bot
gewonnen is german for won
Alright
The next easiest is 1.
The "utility" of a state is the sum of its score and the score of the states that come after it
what do you mean with score?
the score is defined by whether or not the state is a winner state, loser state, or neither
ahh ok
so, if it's a winner state, the score is 1
if it's a loser state, the score is -1
if it's neither, the score is sum of the score of the states that come after it
Yep
We can easily negate that in the 5. function
ok
if you go down to line 264 there is another win function (this is for the 2d list of the bot produces)
I changed the game_over in the case that 'O' wins to -1 and in case that 'X' wins to 1
and also made another elif that tells if it's a tie in which case it'd set it to 0
Alright, good
should I send you the function?
It's all good you can send it later
Next function to implement would be 3.
ok
Do you know how to implement it?
not really if it isn't that what i already wrote in that for loop I told you about
Alright, good then
- would just be applying an action, I see you've already done it
- is the main dish
so 2. and 3. are both basically finished?
what my problem with 3. is ig is the swap between putting in 'O' and 'X'
Well if you assume X goes first, it's X's turn if the number of X and O on the board are equal
yeah I solve the via count%2 == 0: 'X' and count%2 == 1: 'O'
but when I try it in a loop for the minimax it doesn't really work
idk
What do you mean?
in the loop i did for that sometimes the board was full but there were more xs than os, sometimes the board wasn't full and sometimes the count extended over 9 which should be the time the board is full
so i don't know how to make that
That's weird
ik
Maybe we should just write a dedicated function for it
probably
def turn(board) -> str:
if board.count('X') == board.count('O'):
return 'X'
else:
return 'O'
ahh ok thank you
of course you can change it to whatever your representation of X and O are
It's just a type hint
Here, i'm returning a string, so it's a visual hint that the function returns a string
it doesn't behave differently, it's just there for other developers in case they read it
so it's basically like # -> string at the end?
Yep
Except it's special syntax so that IDEs like PyCharm and VSCode can read it and give you helpful suggestions
now I should try to do 2. again
can you help me there too?
so I got it for 1 turn into the future with either 'O' or 'X'
- Is essentially just setting a value in a board
So, erm, it can be like this:
def transition(board: list[list[str]], position: tuple[int, int], turn: str) -> board:
result = [row.copy() for row in board]
i, j = position
result[i][j] = turn
return result
for i in frei:
dummy2[i] = turn(dummy2)
?
is the : again like the ->?
and do I have to use a 3D list or does it work with a 2D list aswell?
Indeed
Not sure what the 3D list will represent
Row and columns of lists?
What will the list represent
sorry was afk for short
yeah rows and columns
the list I use for the 2layerbot is 2d
just index of each field
result is just the result of applying the action
and row.copy() for row in board
dummy2[i] = turn(dummy2)
isn't this all I need for a 2D list?
What's dummy2 supposed to be?
do know understand the use of binray trees
How to determine the storage space complexity of algorithms?
calculate how much it needs to store at one time
the same way you determine the time complexity, pretty much, but with storing stuff instead
poop
Hey folks, does anyone have any good resoures on understanding and implementing ECS systems?
Wow, such quiet lol
yep
no really a ds/algo question, #software-architecture is probably a better fit
Hi! It's been a while since I've hung out here. cool to see this place has blown up. I've been trying to work on my fundamentals recently and would love some help on BSTs.
i noticed whenever i do leetcode problems i stumble more on BST-based problems. its prob cuz i havent used BSTs since college, but I feel like im just misunderstanding how pure BSTs are defined formally.
how i understand them is they are:
- valid if empty
- valid if left subtree node values are < root value
- valid if right subtree node values are > root value
- valid if left child value is < parent value
- valid if right child value is > parent value
in the screenshot I'm reviewing logic to calculate unique BSTs from n nodes (1, ..., n). in my mind once i think of a counter example to the formula you'd want to use I will end up backing myself into a corner. with the root as 2, are any of those BSTs invalid?
i'm trying to do more and more hard-level problems on leetcode but i perform poorly on BST-based medium problems. so i wanna make sure i understand the fundamental data structure. for some reason I see people defining BSTs differently so I'm having trouble poking holes in my logic.
for context I've always enjoyed The Algorithm Design Manual by Steven Skiena. so I've been reviewing that text. I'm assuming I've missed something. I also do fine on problems from leetcode or hackerrank for validating BSTs.
maybe theres actually 5? โ ๏ธ
do you have trouble understanding binary trees?
I think the requirement is
everything in left subtree <= parent
everything in right subtree >= parent
If those BSTs are invalid then I guess so
and yeah, those are the 5 possible ones I think
But given n = 5 Iโm trying to understand how the right side is calculated using f(n-i) if I can generate 5 examples where i=2.
f is the number of bsts with n different values?
Recursively the function G(n) that implements f(i-1) * f(n-i) calculates the number of possible BSTs given n where f(i-1) calculates the possible left subtrees and f(n-i) for the right.
At least how I understand it
In this case i is the root
Youโd sum G(n) over every root
fwiw the number of unique bsts is the same as the number of unique binary trees, which ends up being the Catalan numbers
in short, you can put n different numbers at the top, which splits the tree into subtrees of size (0, n-1), (1, n-2), ..., (n-1, 0)
then
f(n) = sum(f(i)*f(n-1-i) for i=0,...,n-1)
haven't checked my work, but I think that thing is correct
yeah, that ends up being the catalan numbers
The logic for the formula I wrote is simple, n choices for root, n corresponding splits of the tree. For every split we multiply the different configurations of the subtrees f(left_subtree_size)*f(right_subtree_size).
Yea this is what Iโve seen but where f(right_subtree_size) is 3 nodes should that equal 3 unique subtree structures? Thatโs where for i = 2 Iโm stumped since I see 5 unique BSTs.
I feel like this may actually help me tho. If Iโm understanding it properly itโd be 5 for i = 2 maybe?
Hmm maybe I was interpreting the formula incorrectly
the thing you drew up is one of the terms in f(5): f(1) * f(3)
Yea exactly. Thatโs whatโs thrown me off. How Ive understood it itโd be 3
1*5
1*3 sorry. f(2-1) * f(5-2)
Been grinding leetcode all weekend. Pretty brain fried haha
You mean G(3) (if weโre following my diagram word for word)?
whatever you call the number of BSTs ๐
hmm
your G is just one term I guess?
I split the function into left side right side with the fโs and call that G(n) but I think Iโm still confused on unique BSTs with root 2
my f is your f, so that's good at least
I think what Iโm stuck on is are the unique BSTs I created valid? And if so how does that fit into #algos-and-data-structs message. Which is what Ive understood as the solution. But #algos-and-data-structs message I think checks out with what Iโm thinking. Tho Iโm not entirely sure yet.
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
the 5 trees you wrote are valid
Can you elaborate on the math behind f(3)?
as I mentioned f(3) are the trees you drew, ignoring the 1 and 2 that are just...there
Then maybe i am interpreting the material wrong. Ive thought i=2 f(5-2)=3 since logically 3 nodes are available right of 2.
Thatโs kinda the gist of what Ive read
how many ways can you arrange 3 nodes into a BST?
5
yep, these ones
Yea so thatโs where Iโm stumped. What Ive been studying has stated 3 unless Iโm super misunderstanding. Granted none of the material actually โshows the workโ
Really appreciative of the help tho. Been struggling with this for a good chunk of today
what material? the book you mentioned?
Actually I think i 100% misunderstood and I even knew the logic. f(3) is G(3) recursion
Which I think would be the f(3) youโre talking about
G(n) is recursive*
your G is the number of trees if you fix a root
f is a sum of G for all choices of root
The book covers more theory. I tried looking for explanations on forums/discussions.
This
this is from your book
Thatโs where I failed to bring it all together. I was reading too much into verbiage.
(I think it's the right book at least)
I knew it had to be executed recursively but kept seeing โgiven 3 nodes you have 3 structuresโ. I think I misread it that way at least. Itโs given three nodes you have G(3) I think
Which I believe is your point
yeah, I kinda skipped past using G at all when I derived my expression and directly expressed it in terms of f
Iโm pretty confident I get it now. Thanks! Iโll give it another shot tomorrow.
I hope you didn't misread tree as three in some place
ah, "three-node trees" not to be confused with "three node-trees"
Maybe. Iโll see if I can find the examples. I got so desperate that I even watched a couple YouTube videos. So even then I was missing it. I was reading/hearing [1,2,3,4,5] gives you 3 trees.
Yea probably this
Super brain fries ๐
num = random.randint(0,8)
SwitchNum = [num]
def my_num(start):
current= start
while True:
continue current
nums= my_nums(SwitchNum)
for numz in nums:
print(numz)
how can i make work a randint object through a generator?
i have a little bit of trouble understanding the concpet
but i would like my loop to go infinitely through randoms numbers while remembering the last number
can someone help me with this a little bit?
huh ?
You read me right
I have a question regarding solving some M number of equations.
Say I have N number of variables and M number of equations.
I want to resolve them, SUCH THAT
- they ALL should have values more than or eq to 0.
- the norm should be minimum
- the sum of all of them should be 1
What have I done so far?
I have tried to resolve it using lstsq (https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.lstsq.html#scipy-linalg-lstsq)
Issues with it: while it gives least squares, it generates minimum values in solN if required(which is expected).
Can anyone suggest me what else can I try?
Can this be resolved with LPSolver? I can add constraint that they should have positive value, tho then I'm not sure if it will try to find least squared solN.
Okay, so we first note that if M >= N we have either no, or exactly one solution; this probably isn't what you want, so we'll take M < N. You're also probably representing this as a matrix A and the variables by a row/col matrix x.
What do you mean by "they all" are >= 0? The values of A? And the norm of what, the matrix? Which norm? And the sum of what?
EDIT: Had M and N backwards.
yep. No exact soln. It's mostly gonna be M<N.
Whoops, you're right, I had my M and N backwards.
I'll add an example to explain more. It will be more convincing.
say I have 2 eqns.
x + y = 0.5
x + y + z = 1
now It's obvious that this has infinite solNs.
So I'd choose 0.25 0.25 0.5 since it's norm(norm 2) will be minimum and they are all positive.
I have also tried nnls but it's not giving me the least squared solN always, I added another equation at the end saying sum should be eq to 1.
are you guys talking about this expression as in maths? because in python its not possible.
why not?
Why wouldn't it be possible in Python?
how?
also it is possible. I have achieved things so far.
I think they want to just do an optimization problem? Maybe I'm mis-reading?
nope you're right, It's an optimization problem.
They're noting the problem using mathematical notation for the sake of communicating the problem.
oh i mean, you're looking at it the wrong way.
when we say we want to solve
above 2 eqns we make vectors of them and put them in Ax = b form and solve them.
you can solve this as an LP, but it's generally better if you find a linear algebra approach
Even if not: https://www.sympy.org/en/index.html
I thought about it, but would LP minimize the norm too?
the LP would be to minimize the norm given the constraints
it will? then i would like to try it, but i mean i was reading the docs, I can't find it saying, it will minimize the norm.
constrains can be added as they all should be b/w 0 to 1. but how to add constraint for minimizing
I mean, the LP needs to minimize/maximize something
which is linear, and what i want to minimize seems non linear(atleast to me)
Okay. maybe I'm not ready for learning that. anyways, I see a warning on discord here on void linux. I downloaded fresh install but still it's there.
ah, right, 2 norm
this may be the wrong channel for that discussion.
Right, so, that's not too bad working with, but summing things to one is a weirdo thing. So, I gave up doing it on paper and I'm trying brute force on an example to see if I can ween anything from that noise.
yeah I know I'm not gonna discuss on that. I thought if someone have gone through this. I could get a quick answer here. No prob.
What is this for, by the way? I don't think I've seen this kind of structure in Linear Algebra before. Maybe like, cost networks or something?
i kinda thought about softmaxing at the end but that would fuck up the equations right?
see this is the result i get by nnls
however there is solN
0.15 0.15 0.3 0.4 which will have less norm
now I get THAT solN by least squares directly, but for bigger examples it goes in negative too
So I don't get why NNLS fucks up even after they claim its prone to minimize least squares.
sum = 1 and minimize norm seems like an odd constraint 
Yeah, which is why I asked above what this was for, haha.
Some kind of probability thing, but then L2 norm is weird for that.
it is odd but it is required for the paper I'm trying to have practically.
Okay, I have a guess, but this is only because I've only seen this condition once before in my life: does this have anything to do with quantum computing?
not at current stage. no.
sum=1 just to imply that its a PDF.
Ah, I was closer with probability. I'll have to read in a second about why we care about L2.
yeah, I guessed it was probabilities
check page 13.
the L2 norm of probablities was the odd part to me
in a nutshell it defines that our vector is more uniform.
Jez, this is dense. I've not seen much of this notation before.
yeah notations are....well very complex.
my sir has suggested to look upon Groebner basis since it's a non linear problem but I got no idea about it right now.
this paper is a bit over my head, especially after having been out of uni for a while ๐
Huh. I'm not exactly sure why Grobner bases would work, I thought that was for polynomial rings, but I might also have been out too long.
Also, it shouldn't simplify the problem, the bases are fine for optimization --- there wouldn't be any bases, I feel, for which this would be an "easier" problem. We're pretty linear right now, except for L2.
happy to see this kind of advanced topics though, always interesting
Also, I just noticed this, but: what norm are we taking here? For example:
A = np.array([
[1, 1, 1, 0],
[0, 0, 0, 1],
[1, 1, 0, 0],
[0, 0, 1, 1],
[1, 1, 1, 1]
])
x = np.array([0.6, 0.4, 0.3, 0.7, 1]).reshape(1, 5)
y = np.array([1.9, 1.9, 2.3, 2.1]) # xA
understandable. it took quite a lot of my time. I have had very nice results, but some values are getting negative(very small tho), I'm trying to resolve that issue.
We have a few things here. We have the original matrix, which has a norm, we have x (the thing we're multiplying A by) and we have the product.
We prob don't care about A's norm, so it's either x or y?
wait. I think you're mistaken.
It's entirely possible.
norm of (x, y) I thought?
we have y as your x.
so we find X.
given A and y.
Okay, lemme reformulate.
A = np.array([
[1, 1, 1, 0],
[0, 0, 0, 1],
[1, 1, 0, 0],
[0, 0, 1, 1],
[1, 1, 1, 1]
])
y = np.array([0.6, 0.4, 0.3, 0.7, 1]).reshape(1, 5)
find X such that its a pmf(which is in a way taken care by last eqN which i added)
and the X has least norm if there are more than one solNs(which will happen kinda always)
Okay, but where are we getting y from? Is that given to us?
yes.
Ahhhh, got it. And we want to minimize the L2 norm of the vector x, while keeping sum(x) == 1.
exactly.
Okay, I was doing the problem in reverse.
so we have some solution space in x coming from Ax=y, and the remaining constraint is x > 0 and minimize norm?
I think x >= 0, yeah.
and that's the one annoying part, x>=0, otherwise this is trivial
I now understand why LSTSQ was the go-to. Okay, cool.
I mean THAT is the thing that is itching for so long, otherwise least squares were gold.
I guess you either get the correct solution using least squares, or the answer has some components = 0
I guess solving 2^N least square problems isn't feasible?
yes. I am dealing with 400 variables here.
from scipy.linalg import lstsq
A = np.array([
[1, 1, 1, 0],
[0, 0, 0, 1],
[1, 1, 0, 0],
[0, 0, 1, 1],
[1, 1, 1, 1]
])
b = np.array([0.6, 0.4, 0.3, 0.7, 1]).reshape(5, 1)
data = lstsq(A, b)
print(data[0])
[out]
[[0.15]
[0.15]
[0.3 ]
[0.4 ]]
Hm, I'm able to get your solution in lstsq.
I know, it fails on bigger eqns. say 400 vars.
Okay, so this does work on smaller things, though.
not fails, but goes in negative, yeah.
this is for i think 49 vars
gets bit worse in 400 vars
could Lagrangian relaxation be relevant?
I am not aware of this term, lemme check.
from scipy.optimize import lsq_linear
def find_min_norm_nn_vector(n_vars: int = 50, n_eqs: int = 55):
A = np.random.randint(0, 2, size=(n_eqs, n_vars)) # 50 vars.
b = np.random.rand(1, n_eqs)[0]
data = lsq_linear(A, b, (0, 1))
return data
data = find_min_norm_nn_vector(n_vars=400, n_eqs=500)
print(data.x)
[out]
[7.88516441e-003 1.62862014e-034 1.06090201e-035 1.07819825e-034
3.07195273e-002 4.25550093e-034 1.19323658e-002 6.43827861e-036
1.36033363e-032 6.95032406e-035 3.74116037e-029 7.25841010e-035
...
...
sum(data.x)
[out]
1.0099802704176166
This gets pretty dang close.
But, remember: as we increase the dimensionality of our thing, the minimal norm'd vector here will have values closer and closer to zero on average.
I dunno if this matters.
how does this validate that all vals are positive?
wait what is (0,1) here?
I'm not 100% sure, I haven't read their paper yet, this was just an attempt.
7
see the result is very good, except some vals are going negative
Right, that's probably a tolerance issue or something.
no the issue is i was using the least squares only, without constraints, lemme add them
Makes sense. I reproduced your original results with lsq_linear, so that's a good sign.
active_mask: array([0., 0., 0., 0.])
cost: 3.235562306570556e-32
fun: array([ 1.11022302e-16, -5.55111512e-17, 2.22044605e-16, 0.00000000e+00,
0.00000000e+00])
message: 'The unconstrained solution is optimal.'
nit: 0
optimality: 3.3306690738754696e-16
status: 3
success: True
x: array([0.15, 0.15, 0.3 , 0.4 ])
That's pretty cool. Optimization stuff, dang.
I did read this, but it kinda claims, things become faster, i guess currently I'm worried about, more closer to actual should be result, lemme know if I'm mistaken, I've just read it first time.
I've never even heard of Lagrandian Relaxation. Cool, learned some new stuff today, haha.
I've used related techniques for enforcing constraints way back, I just happened to remember the term
This is pretty cool. I haven't done too much optimization stuff, so I only know the very basics. :']
I ran it, hold on, sending some results.s
I'm getting nearer with more equations in hand(which is expected since rank will increase)
but a few remarks to make
This is the values i get using just 1(or if we add sum = 1, then 2) equations.
theoretically, the middle values should be same.
but at the same time the difference is not too vast. I guess what makes it harder practically is that its a PMF, making values falling into smaller and smaller values, which makes it harder for atleast computer to achieve the result because of floating number issues.
moreover this is the original 7 we have(where we want to reach eventually)
So i guess we have kind of very nicely reached over there.
Right, I think that as it grows, it's not getting sparser, it's just spreading the values out, so all the values will be very close to 0. I'm not sure exactly what to do in that case, since it's technically constrained by the constraints of the problem.
I've got to sleep, but I'll check in tomorrow to see if any progress was made!
sure. also thanks a lot @dire plume and @haughty mountain , you both have really been a great great help!!
I'm way more closer now!!
print(main_data)
decoded_data = json.load(data)
filtered_array = []
for country in main_data:
temp_array = []
temp_array.append(country.get(["confirmed"])
temp_array.append(country.get(["recovered"])
filtered_array.append(temp_array)
``` Im trying to convert this array (data)from byte to int. I used json for that. Also it is saying append is invalid syntax
import numpy as np
import matplotlib.pyplot as plt
import pylab as plt
import json
conn = http.client.HTTPSConnection("covid-19-data.p.rapidapi.com")
headers = {
'x-rapidapi-host': "covid-19-data.p.rapidapi.com",
'x-rapidapi-key': ""
}
conn.request("GET", "/country/code?code=it", headers=headers)
res = conn.getresponse()
data = res.read()
main_data = data.decode("utf-8")
print(main_data)
decoded_data = json.load(data)
filtered_array = []
for country in main_data:
temp_array = []
temp_array.append(country.get(["confirmed"])
temp_array.append(country.get(["recovered"])
filtered_array.append(temp_array)
``` whole code
is there a channel where i can ask about something related under automata theory and computability?
This is the closest channel to that i think.
it's something about proving --- is enumerable using the definition of enumerability and making a high level description of a Turing Machine
how do i give a high level description of a Turing Machine to show that this is enumerable?
Oh this is a famous problem. It has been proven in recent years.
yeah the set is empty
But i am not aware of how to do what you said tho. Sorry for that.
The proof has been recent btw.
Fermats conjecture
so umm, for this case im asked to construct a high level description which accepts everything in that form and rejects if otherwise?
does a high level description of a TM does accepts nothing look like this?
M = on input <a,b,c>:
reject
I have no idea about that subject, sorry ๐
#help-honey for a pandas thing if someone can help
Hi people, I am looking for an algorithm to calculate a large number fast enough with high efficiency. Anyone knows something like that?
use bianary?
Nope it's just a massive number that can hardly be emitted with e scientific notations.
what type of algorithm and data structure beginner should know?
this channel has some pinned messages that you might find helpful.
Thanks!
hello folks, currently doing 59. Spiral Matrix II on Leetcode
def generateMatrix(self, n: int) -> List[List[int]]:
ans = [[0]*n for i in range(n)]
i,j = 0, 0
dire = [0,1,0,-1,0]
po = 0
for a in range(1,n*n+1):
ans[i][j] = a
ni,nj = i+dire[po],j+dire[po+1]
if (not 0<=ni<n) or (not 0<=nj<n) or ans[ni][nj]!=0:
po+=1
po%=4
ni,nj = i+dire[po],j+dire[po+1]
i,j = ni,nj
return ans```
I was having trouble solving it, so I looked up the solution. I understand most of the code but am having trouble understanding this part
```py
ni,nj = i+dire[po],j+dire[po+1]
if (not 0<=ni<n) or (not 0<=nj<n) or ans[ni][nj]!=0:
po+=1
po%=4
ni,nj = i+dire[po],j+dire[po+1]
i,j = ni,nj```
if you had posted details people could have looked at it ๐คทโโ๏ธ
get good at using lists
?
Using list comprehension is something I use everyday. Id say a beginner would be best off learning as much about how to work with lists as possible. Everything else can be looked up as needed
That code isn't exactly written to be readable, is it? I made a recursive solution using generators, it's a lot nicer to look at and make sense of imo
def shells(n):
if n <= 0:
return
for j in range(n): yield (0, j)
for i in range(1,n): yield (i, n-1)
for j in range(1, n): yield (n-1, n-1-j)
for i in range(1, n-1): yield (n-1-i, 0)
yield from ((i+1, j+1) for i,j in shells(n-2))
n = 4
res = [[0]*n for _ in range(n)]
for ix, (i,j) in enumerate(shells(n)):
res[i][j] = ix+1
for row in res:
print(row)
in short, generate all the positions (i, j) in order and then put the increasing numbers into the result following that order
the recursion builds the shell (outside layer of the pattern) and recurses to generate the inside
Guys, I've been working on counting the number of units assembled in the factory I'm working. I've developed a code to count them, but I'm facing some troubles
Python windows version does not support pip at all
I'm using Python 3.10.2
I tried in Colab but in that winsound would not work
Due to such troubles, I'm stuck with my work hanging in fate
Plus, I gotta develop a GUI to ensure that the hourly count and overall count is displayed
The factory's end time is not decided in morning itself and hence I gotta develop a command to stop so that total number of units manufactured are displayed at the end of the shift hours
Upon clicking End button
So far, I've been able to develop a code to count within an hour, but at the end of the hour code gets into infinite loop
Pls help
Sorry if I've typed in wrong channel
But this involves some data structures, I feel
here is my code
@slim crest replace 26 with len(self.alphabet)
you might want to have a common function for most of the logic, the code for encode and decode are identical other than a minus instead of a plus
I also don't think you should consume a key character for stuff like whitespace and similar, at least the variants I'm used to
one nice way of dealing with the repeated key is to use itertools.cycle() and then use next to get the next key char as needed
how to make a high level description of a TM to show that this is enumerable?
Hi
I am Bash, And I am too a coder like u guys,
I code mainly Computer Vision and AI , Machine Learning, And i have also made some advanced Detection , and sensory Projects
thanks
i will try that thanks
there are multiple ways to implement binary search right?
like one of the way is
int search(A, key, n)
begin = 0
end = n-1
while begin < end do:
if key <= A[(begin+end)/2] then
end = (begin+end)/2
else begin = 1+(begin+end)/2
return (A[begin]==key) ? begin : -1```
but we can also have different conditions?
like py if key <= A[(begin+end)/2] then end = (begin + end)/2 - 1 else begin = 1 + (begin+end)/2?
like end = mid - 1 or begin = 1 + mid
or end = mid and begin = mid
: /
any guide using which I can plot graphs of price fluctuations of a share using python?
have you tried google?
yes yfinance
you should really try googling things before coming here
๐
it just makes it an inconvience for someone to help you if you havent tried all possible options
but anyway
Learn how to download data, Display Price Charts, Plot Special Event Markers, Shade/Highlight Sections of a Chart, Change Line Color when a condition is true.
Tips and tricks to create useful and telling price charts for trading and investing research.
It has been brought to my attention that Yahoo Finance has changed their API and this code ...
good luck on making money
thanks so much @slim crest i appreciate that
hello can someone please help me here i am using backtracking to solve a sudoko puzzle
but it doesn't work
unexpected attribute 'qaud' to Figure
hi. today i was following the cours and a weird error while trying to run the follwing code,
i was expecting to get a bokeh graph(squares with the function quad) and a interesting resultโฆ an error: can anyone help me understand what the error means and how to fix it? That would mean a lot to me. Thank you.
note: df is a csv file(DataFrame)
please? ๐
: |
"it doesn't work" is not very specific
why the return in the loop?
and you probably want to have a check in the beginning of the function, if completely filled in do something (e.g. print) and return
Fun comes in many forms - playing puzzles, or writing programs that solve the puzzles for you. Professor Thorsten Altenkirch on a recursive Sudoku solver.
https://www.facebook.com/computerphile
https://twitter.com/computer_phile
This video was filmed and edited by Sean Riley.
Computer Science at the University of Nottingham: https://bit...
okay thanks I'll try that
thanks for all the help man
Please forgive me if this is the wrong thread, but I'm a two month novice at Python (worked with OOP, pandas, tkinter, and just starting on APIs) and I keep hearing about how important "DS&A" is. My background is law, government, and literature, so I have almost no prerequisites, but what would you all consider the best resources for such a beginner?
Again, I'm sorry if this is the wrong thread. Thank you.
there's some learning resources in the pins
some discrete math will go a long way when learning about algorithms
depending on what you're doing, you don't necessarily need to know much beyond the very basics
DSA is basically the study of doing an infeasible amount of computation or storing infeasibly large data in a smart way so that it becomes feasible
Thank you.
And I didn't even know "pins" existed, so thank you again.
I want to make a program that's gonna check user input against a json file.
But the problem may be, that the user may mistype a word and therefore it won't be registered:
json = {'0': 'test', '1': 'blabla'}
input = 'tes t'
Error: Input not found!
----------------------
input = 'te5t'
Error: Input not found!
----------------------
input = 'test'
Success: Input found!
Another problem is, that I just can't delete all whitespaces for this (because some inputs need those).
Is there any good library or documentation on how to solve this problem?
Or has anyone an idea and would share it with me?
I'd be happy about any help ^^
https://github.com/AceLewis/my_first_calculator.py/blob/master/my_first_calculator.py what do you guys think of this implementation of a calculator in python
It's horrid @fiery cosmos -- Why not produce a generator and keep the source code compact?
20.8k lines for an example is ... a bit much.
Its a joke repository
Hah, my browser laughed for sure.
Why not just do eval(fโ{x}{operator}{y}โ)
^ that's what I mean. Why'd you post 20k+ lines?
I'll remember the hardlink when I want to dos someone though ๐
Remember...
++++ Watch in FHD ++++
I DO NOT OWN the Video Footages, Images & Music in this Video.
โง แด ษชแด แดแด: Hakuna Matata Scene (The Lion King, 1994 ) #LionKing
For everyone who
WATCHED/LIKED/DISLIKED/SUBSCRIBED/SHARED...
Thank you so much! ๐
"Hakuna Matata; what a wonderful phrase.
Hakuna Matata; ...
I still don't know what 51+50 is
Hey I need help with my minimax algorithm in my tictactoe game
Most of the time it works but sometimes it just makes some mistakes
Hey, i am looping a graph data structure in for loop i made it using a dictionary and i want to access its contents in a range for example dictionary is from A to U and i only want to access its values from A to N i am really confused how i should approach it, is there any simple way to do it?
graph = {
'A' : ['B','C','D'],
'B' : ['E','F'],'C' : ['G','H'],'D' : ['I','J'],
'E' : ['K','L'],'F' : ['M'],'G' : ['N'],'H' : ['O'],'I' : ['P','Q'],'J' : ['R'],
'K' : ['S'],'L' : ['T'],'M' : [],'N' : [],'O' : [],'P' : ['U'],'R' : [],
'S' : [],'T' : [],'U' : [],'Q' : []
}
q = []
visited = []
q.append('A')
visited.append('A')
flag = 1
while q and flag:
x = q.pop(0)
print(x, end = "->")
for i in T[A]:
if i not in visited and i != T[N]:
visited.append(i)
q.append(i)
if i == T[N]:
flag = 0
break```
i tried doing like this but its not working apparently
you want to access the value of the keys of graph dictionary?
I would keep a sorted list of vertices that is easier to deal with. I.e.
vertices = sorted(graph)
for vert in vertices:
if vert > 'N':
break
...do thing using graph[vert]
keys and values both coz they are interconnected
thanks this worked
Hey man, I've worked on a similar project in the past that was a simples dictionary app. repo >> https://github.com/RaphaelLMendes/English_Dictionary
I had a similar issue, and I resolved it using a python lib called difflib that has a function that gets close matches in the dict keys. Check it out, I hope it helps!
Thank you very very much. So far it looks like. I will definitely try it out! Thanks a lot!
Hi!
How can I find the number of binary trees having n nodes and minimum height of h?
(1<= h <= n < 35)
Thanks in advance!
Can you think about how you might approach this recursively?
I can
But I don't know how to handle the minimum height
or height in general
๐ค
The way I'm thinking about it is that at least one of the two sub-trees of the root node needs to have a height of at least h - 1.
yes...
So there are three cases:
- left tall, right short
- left short, right tall
- both tall
If the function takes n and h as arguments, then we can say "any height is ok" by setting h to 0.
But we can't specifically count the number of short trees.
Does that make sense so far? @merry scroll
wdym by "setting h to 0"?
Just do a recursive call where the minimum height is zero.
okay
So we need to add up, for each k in 0, ..., n-1:
count(k, h-1) * count(n-1-k, 0)(i.e. left tall, right any height)count(k, 0) * count(n-1-k, h-1)(i.e. left any height, right tall)
But then we've double counted the cases where they are both tall, so we need to subtract out:
count(k, h-1) * count(n-1-k, h-1)
In other words, for every possible way to distribute the remaining nodes between the two sub-trees, we need to count the number of ways each sub-tree could be constructed, considering the cases where:
- the left sub-tree must be at least h-1 in height,
- the right sub-tree must be at least h-1 in height,
- both sub-trees must be at least h-1 in height.
So why do we need to call for here
Or k will change after each step of recursion?
Well say you have to build a tree of size 5.
One of the nodes will be the root node, leaving four other nodes.
You could put all four in the right sub-tree.
You could put one in the left sub-tree, and three in the right sub-tree.
you could put two on the left, and two on the right.
Etc.
Oh
Would you like to see a solution and have me explain it, or would you like to write a solution yourself?
I'm not sure I'm explaining myself very clearly.
But the code may make it clear.
What is the Time Complexity of this approach?
If you can, that is a great pleasure
With caching, I believe it will be O(n * n * h)
from functools import cache
@cache
def count(n, h):
if h + 1 > n:
return 0
if n == 0:
return 1
total = 0
for a in range(n):
b = n - 1 - a
total += count(a, h-1) * count(b, -1)
total += count(a, -1) * count(b, h-1)
total -= count(a, h-1) * count(b, h-1)
return total
If you don't know what @cache does, it just saves the results from calls to the function, so if the function is called again with the same arguments the saved value can be returned, rather than re-computing it.
๐ค why can't we construct a binary tree with h+1 > n?
Well we can't construct one of that height with only so many nodes.
The tallest binary tree is one where all the nodes are in a line.
That would have height n - 1.
Something a little bit weird: the tree with zero nodes is defined as having height -1.
Just due to the way tree height is defined.
0 |
/ |
0 | height: 3?
/ |
0 |
That's meant to have three nodes right?
Conventionally, that tree would have height 2.
The height is defined as the number of edges on the longest path from the root to a leaf.
Oh
Thank you so much @keen hearth
You are so awesome
Yes.
I made one like this
But without the cache it doesn't work
Yes, the cache is important!
Without it, it's certainly exponential time.
I mean, just look at the answer for count(100, 10)
```
896519947002960918869071082756320105290787033256522147392
It's a weirdly constrained version of Catalan numbers. count(n, 0) should be the catalan numbers
I know
I may have never gotten around to learning about Catalan numbers ๐
Please DM
Hi guys! You may be interested in learning algorithms Steve Wozniak used in his first operating system for Apple-1 - Iโve rewritten it in Python to give an idea what simple operating system do and what are key algorithms. You could get the code from GitHub to play with it - more details here https://twitter.com/smartykite/status/1484057995466186752?s=21
Here is โhelicopter viewโ of 256 bytes @stevewoz operating system for #apple1 rewritten in #Python. Will discuss it at @fosdem and on #SmartyKit webinar. It has a kind of #shell as UI and simple Keyboard and Display โdriversโ as interface to hardware https://t.co/OsojGLzO83
does anyone even come in here
you can judge that by chat above.
Hey, given an R^N space, are there any algorithms in place which would give us some M randomly generated subspaces(by giving their basis vectors) from it?
Basis vectors are important for my case.
It's good to note that we can basically generate infinite subspaces ofc.
that's incredibly beyond me.
i have median, mean, arma with coefficients set to 0.2, savinsky-goloy with coefficients for 2nd order. I have a 6th order HAAR discreet wavelet transform function.
I need, or want, to know how to optimize the combination to best reduce noise for single-channel 16bit audio normalized to between 0 and 1 with a real variance ptp no more than 1.0, which has been represented as 64 bit floating point numbers in a list of 48000 samples per second/48000khz.
I want to focus primarily on white noise reduction.
My linear algebra is hazy but wouldn't choosing M purely random vectors almost always be valid basis vectors? Because it's super unlikely any two lie on the same line or plane 
yeah, it's highly unlikely, but the question is, if I tell you that you are give R^10 now create 10 subspaces for me, how would you algorithmatically do it for me.
what is the case your working in? just because im curious. i am working on a linear audio decomposition project for noise reduction
I forget what a subspace is 
kind of wish i could just make an array of 48000 * 48000 /2 and decompose alllll of the energy in the audio frame into a non-euclydian geometric topology, then apply some kind of fancy algo to it, then recompose it back into audio
A subspace is a space which is a subset of a space.
just a TL;DR spaces are well defined under vector addition and scalar multiplication.
So a subspace of R^10 could be an R^9 or R^8 or R^1 (or trivially R^10 itself I guess)?
that is true, yes, moreover there will be infinite amount of them(like R^2 can have infinite lines passing origin)
theoretically these lines are subspaces. we can imagine higher degrees ofc. like planes.
also not trivially I must add, for R^2, we can even have {[0,1][1,1}
assuming we are not only considering ortho normal basis
So given the 10 basis vectors of an R^N you could select any 2 of them randomly for an R^2 subspace maybe?
my current motto is to select M for any dimension, but we can break it down to find M subspaces for d dimensional subspace. yes.
also, no its not as simple as selecting basis vectors from those 10 if you think about it.
Though, to get any random subspace within R^10 could you generate a random from 1-10 and generate that many random vectors and it's very likely they will be a basis of a subspace 
I might be way off btw
I took linear algebra ages ago, this is just interesting
It's alright! and indeed it is quite interesting.
i mean, if you think about it.
If i narrow it down to say d dimensions.
Putting things in place.
we will have vectors of size n (however for all of them the n-d will be 0)
So we can first choose d random dimensions for each vector (say for n=4, and d=2, and m=2)
for mi = 1,
we chose [0,2]
dimension for first vector, and creating a basis we have [1,0,5,0]
creating another basis we have [3,0,2,0]
So we found a subspace {[1,0,5,0], [3,0,2,0]}
Same way for mi=2 perhaps.
Now this can be done.
but I mean I am searching for, is there any existing way to do this?
which will choose best subspaces. And yes, I do not YET know what do we mean by Best here very precisely.
can anyone help me ?
I have a test on data structures and algorithms in 4 days
i need help
yes I live here
i have two 1d lists of X elements of floating values
one comes after the other, in a chronological sense
so ascending
I need to take the end of one list and the beginning of the second and efficiently smooth their values together to eliminate a discongruity
take as in remove them?
no?
by "end" and "beignning i dont mean last value- i mean something more like last, first 200 values, where the trend is smoothed
ohh okay
use list indices
arr[x:len(arr)]
smooth together?
i think you might be better suited to #python-discussion because you don't seem to care about what i'm asking but rather how you can explain simple things like syntax
i need algorithm help, not syntax help brah
@rare dawn does this allow numpy?
this is either an essay or homework
why are you trying to get a programming job if you cant program
the question is actually asking you to sort a list of arbitrary size, then search it for zero, then find the value right above zero, then count upwards to see if each value is the same as the index, then return the index of the first value where it's not the same.
For negative integers, the assignment is slightly more complex.
For negative values, you're being asked to disregard them and simply return the smallest positive number, which means you need to discard all elements of the list which are negative, sort those which are positive, assign those which are positive to indices, and then search through it. good luck
are you trying to be a programmer?
I come from a heavy cybersecurity background
and trying to move into software engineer
@haughty mountain i see u typing
@rare dawn this is a test to evaluate your programming skills. This is not actually a data structure question, it's a basic interview question.
duh
Silly idea: pick a random unit vector, project the basis along that direction, you now have a N-1 dimensional space spanned by N vectors
Compute an N-1 dimensional ON basis from the N projected basic vectors.
Repeat until you reach your desired subspace dimension.
i really appreciate your help
i am trying the problem
@haughty mountain given a list and a desired end value, how would you convolve it to gradually bring it to that point near the end
this is about the smoothing question?
no need to sort things, put everything in a set or equivalent and just check whether 1, 2, ... exist
you can use a length N array of booleans as a set in this case to have true O(1) operations
oh okay lemme try that
please help me
someone call me
explain
for love of god
what I wrote is the whole approach to the task
Thank you
it's like...3 lines to implement
where?
put everything in a set or equivalent and just check whether 1, 2, ... exist
and it's a stupid short implementation
yea lol
im still lost
with
!d set
class set([iterable])``````py
class frozenset([iterable])```
Return a new set or frozenset object whose elements are taken from *iterable*. The elements of a set must be [hashable](https://docs.python.org/3/glossary.html#term-hashable). To represent sets of sets, the inner sets must be [`frozenset`](https://docs.python.org/3/library/stdtypes.html#frozenset "frozenset") objects. If *iterable* is not specified, a new empty set is returned.
Sets can be created by several means:
โข Use a comma-separated list of elements within braces: `{'jack', 'sjoerd'}`
โข Use a set comprehension: `{c for c in 'abracadabra' if c not in 'abc'}`
โข Use the type constructor: `set()`, `set('foobar')`, `set(['a', 'b', 'foo'])`...
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
Thank you i know this as other words so your help is help me alot
im a Pentester not a programmer
cool
sorting might still be faster, though
I'm not well versed enough in signal processing to know a good principled way of doing this ๐ฆ
You can probably just convolve the relevant portion of the signal with a gaussian and get something good enough.
guys im still stuck
how
sorting will for sure not be faster than doing a set using a bool array, which is akin to counting sort, assuming I'm in a language where I can actually write performant code
idk how to "convolve with a guassian
i know how to convolve, but not how to convolve with a guassian
i have ARMA and savitsky-goloy accelerated 1d window of 5 second order functions i built
i haven't actually benchmarked, but I'm just saying it might be faster still to sort ยฏ_(ใ)_/ยฏ ๐ฅด
ah, I see that edit
I have a test ๐ญ
Please help
im cry
dont want to fail
i feel so lost
also due to stress i feel im not understand simple things
can someone write my code for me? i need someone to help me make my convolution function work to "convolute with a gaussian" whatever that is
not code
I mean just convolving with a gaussian as a window function, it's a very iffy solution though. Not guaranteed to work well in general
@numba.jit(numba.float64[:](numba.float64[:]), nopython=True, parallel=True, nogil=True,cache=True)
def savgol(data: list[numpy.float64]):
coeff = numpy.asarray([-0.08571429, 0.34285714, 0.48571430, 0.34285714, -0.08571429])
#pad_length = h * (width - 1) // 2# for width of 5, this defaults to 2...
data_pad = numpy.zeros(data.size + 4)
data_pad[2:data.size + 2] = data[0:data.size]#leaving two on each side
firstval = 2* data[0] - data[2:0:-1]
lastvals = 2* data[-1] - data[-1:-3:-1]
data_pad[0] = firstval[0]
data_pad[1] = firstval[1]
data_pad[-1] = lastvals[1]
data_pad[-2] = lastvals[0]
new_data = numpy.zeros(data.size)
x = numpy.zeros(((data.size-2),6)) #create array for outputs
for i in numba.prange(2, data.size):
x[ i - 2,0] = data_pad[i - 2]
x[ i - 2,1] = data_pad[i - 1]
x[ i - 2,2] = data_pad[i]
x[i - 2,3] = data_pad[i + 1]
x[i - 2,4] = data_pad[i + 2]
x[i - 2,5]= data_pad[i + 3]
#
#multiply vec2 by vec1[0] = 2 4 6
#multiply vec2 by vec1[1] = - 3 6 9
#multiply vec2 by vec1[2] = - - 4 8 12
#-----------------------------------------------
#add the above three = 2 7 16 17 12
z = numpy.zeros((data.size, 30))
for i in numba.prange(data.size):
for n in numba.prange(30):
for k in numba.prange(5):
for gk in numba.prange(6):
z[i,n] = coeff[gk] * x[i, k]
#create the array of each set of averaging values
for i in numba.prange(data.size):
new_data[i] = numpy.sum(z[i,:])
return new_data
given this function
how would you make it into a guassian?
are you taking it right now?
well, in 5 days, come ask me for help and i'll write your code for you
i just want to understand
now if i had a girlfriend i might consider writing it sooner, but i dont, so im going to drink coffee and watch anime instead
i want to understand this things
what? that's against our rules and also will not help them learn
its not against the rules to write code for people. i said in 5 days, which is after their test ends @grizzled schooner
to understand not just give code
arguably it is against the rules now, since they told you not to
people
I don't think a helper decides the rules. Moderators might
anyway they're in the wrong channel
@rare dawn go to #python-discussion
are you going to help or talk about rules while an innocent soul is here crying for help
?
you so rude
im ask for help
innocence must be established before the court of courtney freakin miller
so no help ?
what do you need explained
what in particular don't you understand?