I have one application of WinForms
which inside list box I am inserting name and price..name and price are stored in two dimensional array respectively. Now when I select one record from the listbox
it gives me only one index from which I can get the string name and price to update that record I have to change name and price at that index for this I want to update both two dimensional array name and price. but the selected index is only one dimensional. I want to convert that index into row and column. How to do that?
But I'm inserting record in list box like this.
int row = 6, column = 10;
for(int i=0;i<row;i++)
{
for(int j=0;j<column;j++)
{
value= row+" \t "+ column +" \t "+ name[i, j]+" \t " +price[i, j];
listbox.items.add(value);
}
}
Use reshape() Function to Transform 1d Array to 2d Array The number of components within every dimension defines the form of the array. We may add or delete parameters or adjust the number of items within every dimension by using reshaping. To modify the layout of a NumPy ndarray, we will be using the reshape() method.
So the total number of elements of 1D array = ( m * n ) elements. Call the function input_array to store elements in 1D array. Call the function print_array to print the elements of 1D array. Call the function array_to_matrix to convert 1D array to 2D array.
In this array, the position of data elements is defined with two indices instead of a single index. In Python, we can access two-dimensional array elements using two indices. The first index refers to the list's indexing and the second one refers to the elements' position.
Java specifies arrays similar to that of a "row major" configuration, meaning that it indexes rows first. This is because a 2D array is an "array of arrays". The second illustration shows the "array of arrays" aspect.
While I didn't fully understand the exact scenario, the common way to translate between 1D and 2D coordinates is:
From 2D to 1D:
index = x + (y * width)
or
index = y + (x * height)
depending on whether you read from left to right or top to bottom.
From 1D to 2D:
x = index % width
y = index / width
or
x = index / height
y = index % height
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With