# Category Archives: StackOverFlow

Stack Overflow is a question and answer site for professional and enthusiast programmers.

# recursion within a class

I am trying to place a recursive formula inside a class statement

``````class SomeNode:

def __init__(self, a):
leng = len(a)
half= leng/2
self.firstnode=a[0][0]
self.child1=SomeNode([a[i]for k in range(leng)])
self.child2=SomeNode([a[j] for j in range(leng)])

def recursfunc(self):
print self.firstnode
recursfunc(self.child1)
recursfunc(self.child2)
``````

However I keep getting the error message NameError: global name ‘recursfunc’ is not defined

# How can I multiply two matrices in C#?

Like described in the title, is there some library in the Microsoft framework which allows to multiply two matrices or do I have to write my own method to do this? // I’ve got an answer to this by now

Second question:
I wrote this multi class with a MultiplyMatrix method but it doesn’t work like I want to. Can anyone help and tell where I made a mistake?

``````class multi
{
public void MultiplyMatrix(double[,] _A, double[,] _B, int _n, int _m, int _r)
{
int n, m, r;
double si;
n = _n;
m = _m;
r = _r;
double[,] A = new double[n, m];
double[,] B = new double[m, r];
double[,] C = new double[n, r];
A = _A;
B = _B;
try
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < r; j++)
{
si = 0;
for (int k = 0; k < m; k++)
{
si += A[i, m + k] + B[k, r + j];
}
C[i, r + j] = si;
}
}
for (int i = 0; i < C.Length; i++)
{
for (int j = 0; j < C.Length; j++)
{
Console.Write(C[i, j]+" ");
if (j % 3 == 0)
Console.WriteLine();
}
}
}
catch (IndexOutOfRangeException) { } // I always get this exception

}

}
``````

# How do I create a suggestion drop-down list like Google’s?

It’s a theoretical question at this point in time, but something I’m probably going to want to do long-term.

When you go to google.com and start typing a search, it’ll provide you with suggestions in a little drop down menu. I’m reasonably certain that they use AJAX to send what you’ve typed and get a list of possible suggestions back. What I’m trying to figure out is how they actually display that list. It looks like a simple <select> drop down list, just without the actual select box at the top. There is zero doubt in my mind that it’s something as stupidly simple as a CSS trick that divides the select box from drop-down list it produces or an input type other than select, but I’m drawing a blank.

# Format number to always show 2 decimal places

I would like to format my numbers to always display 2 decimal places, rounding where applicable.

Examples:

``````number     display
------     -------
1          1.00
1.341      1.34
1.345      1.35
``````

I have been using this:

``````parseFloat(num).toFixed(2);
``````

But it’s displaying `1` as `1`, rather than `1.00`.

Format number to always show 2 decimal places

# Working with onStateChange of Youtube player

I was trying to use the `onStateChange` property of Youtube videos, And I could not get it to work. I searched a lot over it but could not really understand how it works. Here is the code which I tried, I added a console.log, which does not get called. Can someone help me?

This is my code:

``````    <script type="text/javascript">
var player = document.getElementById("YTplayer");
}

function onplayerStateChange(newState) {
console.log('test');
}
</script>
<object style="height: 390px; width: 640px">