I want to find the index of array which get the value 1. for this purposes I have function which arg. In this example I want to see index 1 and Index 4 as a result.But the result that I see is
What's the point of line 24 though? You can delete that line and still get the same result.
In fact, you don't need the bestIdx variable either. You already have i
One last point: be careful when using == with double values, there are cases where you won't get the expected result because of the way floating point values work.
In this example I have a 2D-array which is decisonVar. when the value of decisonVar is equal to one the indexes of array is printed.
This is the output of program:
*Decision Variable*
[0][0]=1
[0][1]=0
[1][0]=0
[1][1]=1
[2][0]=0
[2][1]=0
**ArgMax**
[0][0]=1
[1][1]=1
what if I do not want to print this index in the method. I want to use return. For example the value [0][0] is return back by this method. then value [1][1] is returned back by this method.Is it possible?How can I do it?
If you want to return both the row and column indices for multiple places you need two things: a class that will hold a row and column number, and a List that will hold multiples of those. You could do it with an array instead of a List but it is messier.
Then either return a List<RowColumn> or RowColumn[].
This is an example of returning an array instead of a List. A List has the advantage of growing as needed, whereas you have to pre-allocate an array with a fixed length. Two problems with this: 1) how do you guess the size you'll need for the array, and 2) any array positions not filled will contain null.