Convert 3d Array To 2d Array

When working with 2D arrays (matrices), row-major vs. ' * If 1D array is given to this function, the result will be 2D array with one ' column and as many rows as the source array. I want the 3rd dimension to be concatenated along dimension 1 in the 2d matrix. The unfortunate part of creating a 2D array with references is that the 2D array does not have its own memory space. I am having an issue creating a VI to convert a 2D array into a 3D array based on a value from a column in the 2D array. take a 2d numpy array of category labels and turn it into a 3d one-hot numpy array - 2d_to_3d. array([[1,2], [3,4]], dtype=object). You may also wish to read /mac/00help/archivepolicy. I'm weak in math, I need a. Each elements can be accessed by operator[] like array[index]. In the C programming language, using an array to hold the frequency count simplifies creating a histogram of your data set. , a data frame) or via as. 2-Dimensional Array. That means your program should reverse the given array in place. They build full-blown visualizations: they create the data source, filters if necessary, and add the. You can use subscripts to either to retrieve the value of one or more array elements or to designate array elements to receive new values. An example how to convert numpy arrays to ctypes 2D and 3D arrays, parse them to C, and get them back after running a C function. 2d NDArrays have a rank of 2, 3d arrays have a rank of 3, and so on. 2D Plotting Example 2: Plot. select mdsys. You should convert all of the inputs to the same numeric class,. Enter a thickness value for the selected surface on the command line. We know these are 2D arrays as the second dimension specifies how many rows in these arrays and the third dimension the number of columns. You can slice a 2D array out of a 3D array with both ways of coding, or even “logic array [width][depth][height]”. My current code, using Shapely, does flatten from 3D to 2D, but it relies on the geometry's wkt method outputting as 2D (even if it is 3D). But the code does not work. Maintains legacy command line behavior for creating nonassociative, 2D rectangular or polar arrays. Getting Started with 3D Graphics on Android OpenGL ES. In C programming, you can create an array of arrays. Is this not a thrilling development? This 3D modeling technique was earlier reserved to professional 3D designers and film studios only. The following are code examples for showing how to use keras. Let's say I have a 2D numpy array, all filled with zeroes and ones. convert 2d array to 1d array without using shift registers and build array. The inputs are the 2D array to search and the element you want to search for. Processing Forum Recent Topics. How to Deserialize a JSON array in C# Jul 21 2015 2:34 AM I am struggling with a subject that has a lot of variants in this forum but I can't seem to find one that suits me, and I think it's because of the way that my JSON array is :( I'm not an expert but I already manage to "almost" get the end. To refresh your memory here is the coordinate system that OpenGL uses which is the 3D Cartesian Coordinate System. The programs. tolist() #> [1, 'a'] To summarise, the main differences with python lists are: Arrays support vectorised operations, while lists don't. If you read an image in color form , It will use 3 2-d arrays to store image ,1 array for each channel B,G,R seprately , but if. You could even use np. To get an idea of how you build and use array formulas in an Excel 2013 worksheet, consider the sample worksheet. Nov 12, 2015 Array, Core Java, Examples, Snippet comments. Thus if a same array stored as list will require more space as compared to arrays. toString() method prints whole array in one go. Active 12 months ago. Steps to creating 2D array using pointer to pointer. Each element, therefore, must be accessed by a corresponding number of index values. We'll start with a simple helper method that gets a column, as a sequence, from a 2D array. This Java array tutorial explains how to work with Java arrays. array and we're going to give it the NumPy data type of 32 float. , Dim V(1 To 3) As Long), the function will return True. This object is defined in the file arraytmpl. Ask Question Asked 11 months ago. using System; To List: convert query result to list: 5. matrix if it is two-dimensional (e. 3D programming in python. If X is not an array but an object of a class with a non-null dim value (such as a data frame), apply attempts to coerce it to an array via as. microedition. It's FREE too :) Download source code at: How To Convert pdf to word without software - Duration: 9:04. deepToString(Object[]) method is a java. Ask Question We can convert to a matrix by calling the matrix and specifying the from 2d array (dims NxKK) to 3d array (dims NxKxK. Pretty easy with a Numpy array. How can I plot a 3d surface in matlab? Question. The code itself is provided below. You can also declare an array of arrays (also known as a multidimensional array) by using two or more sets of brackets, such as String[][] names. If you have a lot of numeric arrays you want to work with then it is worth using the library. Here i can see more feasible and efficient code for converting Multidimensional array into CSV file. If you want to convert a table to a table (which is all a 2D array is) then you'll have to generate an array with N columns where N is testDataSet. Function returns a 3D array (p x k x n), where p is the number of landmark points, k is the number of landmark dimensions (2 or 3), and n is the number of specimens. It also provided various output features like PS plots, TIFF/PNG/PICT/ASCII files. sortWith all return the sorted array as a new array. In 1-based schemes, -1 generally would indicate the second-to-last item. Arrays that treat the pixels as a single integer are referred to as 2D arrays. You can go from a 2D array to a 3D array by using a combination of ndtooned, onedtond, and possibly reordering commands. What do the vectors mean in T? T is a 4*4 column-major matrix. When I run a script with this array, I'd like it to create a PNG image with each zero interpreted as a white square and each one interpreted as a black square. Adding New Elements on the Fly. In Java, a table may be implemented as a 2D array. We know these are 2D arrays as the second dimension specifies how many rows in these arrays and the third dimension the number of columns. You could convert your 2-dimensional array into a doubly jagged array (an array of arrays) and then convert that to a pointer to a pointer and then pass that to C++. Say that I have a color image, and naturally this will be represented by a 3-dimensional array in python, say of shape (n x m x 3) and call it img. Previous: Write a NumPy program to convert 1-D arrays as columns into a 2-D array. 2d NDArrays have a rank of 2, 3d arrays have a rank of 3, and so on. With each iteration of that loop, lngPosition will count up from 0 to 6. The array can hold 12 elements. A dynamic array is an array data structure that can be resized and which allows elements to be added or removed. RF-Brush senses the 3D orientation and 2D movement of the linear shaped object, when the human subject is drawing with this object in the 3D space. fromfunction Construct an array by executing a function on grid. I want a new 2-d array, call it "narray" to have a shape (3,nxm), such that each row of this array contains the "flattened" version of R,G,and B channel respectively. Is there a way to use pointers and not reallocate a new 1d array and just keep the allocated 3D array. Previous: Write a NumPy program to convert 1-D arrays as columns into a 2-D array. To visualize this data, we need a multi-dimensional data structure, that is, a multi-dimensional. Each element of the 'jagged' array is itself an array, so you may do something like this: jagged[0] = new string[]{"Bye"};. Numpy arrays have contiguous memory allocation. matrix if it is two-dimensional (e. In Numpy dimensions are called axes. Your C++ class is managed and can easily and trivially handle a managed array (including a 2-d array). Getting Started with 3D Graphics on Android OpenGL ES. Write A Program To Sort One Dimensional Array In Ascending Order Using Static Method. Learn more about 3d array. Please explain what you're trying to do, and we can suggest a solution. Same Program in Other Languages. Multidimensional Arrays in Excel VBA. WELCOME TO MAC. It can be a two-dimensional array or three-dimensional array or more. How to convert a 3D line into a 2D line?. Same Program in Other Languages. A For Each Loop is used to loop through each element is a Collection, or an Array. Iterate via for loop to take array elements as input, and print them. 2D and 3D rotations, 3D. newaxis in the index. The slices in the NumPy array follow the order listed in mdRaster. squeeze(), which will eliminate any singleton dimensions (but I personally hate using it because it can accidentally squeeze out dimensions that you didn't intend to squeeze when you have arbitrary input data). This page provides a couple of methods for converting 2D data into 3D data that can be viewed with VisIt. Python - Converting 3D numpy array to 2D. Then four such 1D arrays are placed one below the other to give a 2D array containing four rows. Questions: I am interested in knowing how to convert a pandas dataframe into a numpy array, including the index, and set the dtypes. Given a 2D array, sort each row of this array and print the result. This VI uses the function "Search 1D Array" to search a 2D array in the same fashion. if you have an array 'strings, you'll get a DataTree of strings. A three-dimensional (3D) array is an array of arrays of arrays. 2 NaN 2 NaN NaN 0. Convert a pandas dataframe in a numpy array, store data in a. Active 12 months ago. 8 ? 15 _____ 17 27 x 34. Hi all, I need to read a text file (I've attached it, you can take a look), and then store all the numbers in it into a 2D array. Latest updates on everything 2D to 3D Video Software related. Since arrays can store LOTS of data, and since we have only a small (~32) number of registers, it is infeasible to use the registers for long-term storage of the array data. The second approach is to use the values attribute…and this also produces a NumPy array. In JSON, array values must be of type string, number, object, array, boolean or null. Data frames combine the behaviour of lists and matrices to make a structure ideally suited for the needs of statistical data. for (int i = 2. An array of arrays is known as 2D array. Featured 2D to 3D Video free downloads and reviews. First of all, the byte type in Java is an 8-bit signed two's complement integer. For any n-dimensional rotation matrix R acting on ℝ n,. It's FREE too :) Download source code at: How To Convert pdf to word without software - Duration: 9:04. Note that if you have an actual question, I strongly suggest that you do that, ask a question (I don't see one above), and also provide enough information so that it's answerable (right now as far as details, you don't give much). Returns a string representation of the "deep contents" of the specified array. All elements are stored one after the other in memory, resulting the the same memory usage as one-dimensional arrays. Or, you can use the Reshape Array function. You can use np. Each element, therefore, must be accessed by a corresponding number of index values. Rebuilds arrays divided by dsplit. This page contains SystemVerilog tutorial, SystemVerilog Syntax, SystemVerilog Quick Reference, DPI, SystemVerilog Assertions, Writing Testbenches in SystemVerilog, Lot of SystemVerilog Examples and SystemVerilog in One Day Tutorial. RasterToNumPyArray supports the direct conversion of a multidimensional raster dataset to NumPy array. The example concludes. The GAArray object The squares are elements in the array. array of bool. Converting from 2D to 1D is easy, since you just concatenate all values. Converts a subset of an 8-bit unsigned integer array to an equivalent subset of a Unicode character array encoded with base-64 digits. Each variable in a Java Array is called an element. The array of pixel values in a 3D image may be obtained using ImageData. This may be more efficient. /* * Copyright (c) 1995 - 2008 Sun Microsystems, Inc. Formulas for 3D Arrays convert C program for Array to. It is a scalar or an array of the same length as x and y. You have one RGBA color for your quad while GL wants one color per vertex. multi-dimensional array in Java are also referred as array of array because in each index of first array another array is stored of specified length. I'll go over both of the 2 major methods (Vector vs Pointer). First create a matrix "twoDmatrix" to convert, then create the 2D-list as described above with "head" as pseudonode pointing at the 2D-list, then print the matrix and the 2D-list respectively for checking purposes. Here i can see more feasible and efficient code for converting Multidimensional array into CSV file. It has to be said that one-dimensional arrays are fairly easy - it is when we reach two or more dimensions that mistakes are easy to make. array 2D to 1D. Arrays manipulations methods. The outer array has 10 elements. array_push() treats array as a stack, and pushes the passed variables onto the end of array. Here, x is a two dimensional array. An example how to convert numpy arrays to ctypes 2D and 3D arrays, parse them to C, and get them back after running a C function. In 1-based schemes, -1 generally would indicate the second-to-last item. Description¶. please help me, i have an interview on wednesday. Note that the data type of index array is GLubyte instead of GLuint or GLushort. Hi Guys, I trying to convert a 1d array into a 2d array using a fuction. Lesson 15: Matrixes and 2D Arrays Published Friday, 3D array of integer numbers Convert to bold Convert to italic Convert to link. 3D programming in python. All elements are stored one after the other in memory, resulting the the same memory usage as one-dimensional arrays. First, we will allocate memory for an array which contains a set of pointers. Here is theory on the concept No matter how many dimensions are there, memory of an array is assigned linearly. Configurability of point format would draw a significant performance overhead, so if you use a different format, e. Why is my "grayscale image" a 3D array; can I convert to 2D grayscale without sacrificing quality? by taking a screen shot, copying to Paint and converting to. The syntax is shown for these arrays. scipy array tip sheet Arrays are the central datatype introduced in the SciPy package. It can sometimes be useful to think of it this way, but underneath it's really a really long 1D array and the accessor method is smart enough to convert the two integers into the single index (it's not that complicated, it's just rowToAccess * totalColumns + columnToAccess). …I should note that either of these approaches works…just as well as the other. How do I convert this object to be a solid 3d object when. And thank you for taking the time to help us improve the quality of Unity Documentation. In addition, if the 2D array was going to be an unknown length you can't create an unlimited number of 1D arrays to handle this situation. By default, the maximum number of array elements that you can generate in one command is 100,000. (Combined with the robot odometry) This means I need to have some coordinates. For example, the following declaration creates a two-dimensional array of four rows and two columns. Say that I have a color image, and naturally this will be represented by a 3-dimensional array in python, say of shape (n x m x 3) and call it img. Directly creating a Java 2D image and rendering to it. You need not to convert any image in 2-d array as most of the image processing libraries stores images as a 2-d array. Arrays - VHDL Example Create your own types using arrays. Help with File I/O as Binary file C, array of structure; Need help with C prog (average of a 2d array row and all of the array) c# Array. In C programming, you can create an array of arrays. Formulas for 3D Arrays convert C program for Array to. sortBy, and Array. Each array in the double array parameter represents a single ring of the polygon. Table of Content. It is a fixed collection of same data type that are stored contiguously and that are accessible by an index We specify their length and we can initialize arrays with data. Re: how to declare a 2D array in python if it is going to be a sparsley populated array, that you need to index with two integers, you might find that a dictionary with a tuple (x,y) as the key might work just as well. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. A three dimensional (3D) array can be thought of as an array of arrays of arrays. 4 thoughts on “ How to Copy One Array to Another in Java ” Barakehud May 8, 2016. Thus it is easy to convert a program written with static array to make it work with dynamic array. Array manipulation, ordering, searching, summarizing, etc. This module contains classes representing coordinates in spatial, celestial, and terrestrial coordinate systems, as well as implementations of transformations between many of the coordinate systems. Introduction This article discusses about the Two Dimensional To Three Dimensional conversion and vice versa in c++ The following program converts two dimensional array to three dimensional array using TwoDimToThree() and converts three dimensional array to two dimensional array ussing ThreeDimToTwo(). If 1D array size is more than the 2D array size, then the elements that can be fit into the 2D array will be inserted, remaining however will not be inserted. array that you created before. Matplotlib syntax and function names were copied as much as possible, which makes for an easy. I have a (71680 x 8) 2d matrix and I need to make a 3D matrix of dimensions (512 x 8 x 140) I need to take (512 x 8) consecutive matrices by row for 140 layers. How many chairs are in the auditorium. Join 1D three arrays together become a 1d array. Arrays are useful and fundamental structures that exist in every high-level language. I'm trying to create a gear by drawing a circle and a single tooth for a gear, then using a polar array to create teeth around the circle. Function returns a 3D array (p x k x n), where p is the number of landmark points, k is the number of landmark dimensions (2 or 3), and n is the number of specimens. So I'll post up some info that will hopefully help other people. zip and Array. Take n, a variable which stores the number of elements of the array, less than maximum capacity of array. 2D image stacking as 3D numpy array with Python and Raspberry Pi I'm working on a Raspberry Pi project in which I need to take about 30 images per second (no movie) and stack each 2D image to a 3D array using numpy array, without saving each 2D capture as a file (because is slow). Forms? This site uses cookies for analytics, personalized content and ads. Outer loop is responsible for rows and the inner loop is responsible for columns. array(img) # Convert array to Image img = PIL. Before learning multidimensional array, visit Java array article to learn about one-dimensional array. I don't see how this makes a 2D array in to a 1D array. A three dimensional (3D) array can be thought of as an array of arrays of arrays. If we program with numpy, we will come sooner or later to the point, where we will need functions to manipulate the shape or dimension of arrays. convert_2d_srid_to_3d(8307) from dual; Sometimes, you may not be able to get any equivalent SRID in the 3D space that corresponds to the one in 2D space. This article contains the difference between one-dimensional and two-dimensional array. If an integer, then the result will be a 1-D array of that length. Change a 2D Array into a 1D Array. However, this article is about implementing array operations using the basics provided by Python. Signal Processing Resource Center » Vision Development Module Image Processing Examples » Image To Array Example. A single solution to convert the entire class of 2D images to 3D models does not exist. This is a simple way to stack 2D arrays (images) into a single 3D array for processing. An array of arrays is known as 2D array. I am currently doing this as follows:. Machine learning data is represented as arrays. Note that, when 2D array size is more than the 1D array the remaining places in the 2D array will not be filled. If ' an array of variants contains an uninitialized element (VarType = ' vbEmpty) that element is skipped and not used in the comparison. If the array contains other arrays as elements, the string representation contains their contents and so on. From just one or two photos of you or your loved ones, you can have the image reconstructed in a 3D photo in glass. What do the vectors mean in T? T is a 4*4 column-major matrix. Fornux Calculator Student Edition v. Maintains legacy command line behavior for creating nonassociative, 2D rectangular or polar arrays. 3 and Ubuntu 12. 0 or ARB_texture_cube_map_array) For 2D array textures, the number of array layers in each mipmap level is the depth value. All Forums. My main questions are:. Iterate via for loop to access each element of array to get sum (sum of positive integers and negative integers are separate) and overall sum to calculate. a: array_like. newaxis comes in very handy when you want to explicitly convert an 1D array to either a row vector or a column vector. for (int i = 2. So I'll post up some info that will hopefully help other people. Same Program in Other Languages. List have many functionality that ordinary array do not support. If used correctly the data structure can behave as a two-dimensional or multi-dimensional hash. Here is theory on the concept No matter how many dimensions are there, memory of an array is assigned linearly. 2d NDArrays have a rank of 2, 3d arrays have a rank of 3, and so on. Julia, like most technical computing languages, provides a first-class array implementation. Next, we will allocate memory for each. dataframe: label A B C ID 1 NaN 0. I wanted to know how to convert 1D array to 2D array and 2D array back to 1D array in c programming. Under GLSL 4. Split() : to transform a string into an array, according to the separator which is placed in parameter. My main questions are:. It also demonstrates * how to load an image from a file (such as a JPG). Parameters specify the subsets as offsets in the input and output arrays, and the number of elements in the input array to convert. Advantages: The advantages of using a flat array are improved performance and interoperability with C++ or other languages. Arrays and Tuples. Finding the 2D pixel coordinates of a 3D Point Explained from Beginning to End. Then we can use pointer arithmetic to index 2D array. may_share_memory() to check if two arrays share the same memory block. So I want to store the n 2d arrays in a 3d array of form. Previous: Write a NumPy program to concatenate two 2-dimensional arrays. Two-dimensional (2D) grayscale images (such as camera above) are indexed by rows and columns (abbreviated to either (row, col) or (r, c)), with the lowest element (0, 0) at the top-left corner. How do I convert an index for a one-dimensional array into x and y? Ask Question Asked 3 years, 6 months ago. Vector based multi-dimensional arrays. C allows for arrays of two or more dimensions. Program which shows content of a given 2D array ; Program to illustrate the 2D array of int using pointers; Program to illustrate the 2D array of char (string) using pointers; Program to read 2D array and display it row by row and its sum; Program to declare, initialize and print a 2D array of integers; simple queue with array. Maintains legacy command line behavior for creating nonassociative, 2D rectangular or polar arrays. I wanted to know how to convert 1D array to 2D array and 2D array back to 1D array in c programming. The AutoCAD tutorials section contains a range of tutorials from beginner to advanced and covering both 2D and 3D. 0, this can also be an array of objects. s: Size in points^2. Hi, Hope someone can help, I have a 2D array of 1062 x 300 doubles in the format of Xn Yn Zn and I am trying to convert it into a 1062 x 100 x 3 matrix where each of the 3 dimensional points are collected together. This is because it is treated as an M (M=1) by N matrix and is plotted as N plots with M (M=1) elements in each plot. dataframe: label A B C ID 1 NaN 0. An N element array (converted to a 2D array) is plotted as N plots with 1 element in each plot. > > You can go from a 2D array to a 3D array by using a combination of ndtooned, onedtond, and possibly reordering commands. They might seem very similar, but while the first is an array that just happens to have 2 dimensions, the second is an array of arrays. 0 Compute simple arithmetic to high-precision calculations (up to 60 digits), render beautiful 2D/3D graphics and histogram/scatter plot quickly with smart formatting, trace your graphic coordinates and send professional reports in seconds. Hi to all, Oracle 9. You can think this array as table with 3 rows and each row has 4 columns as shown below. C++ Programming Code for Three Dimensional (3D) Array. if you have an array 'strings, you'll get a DataTree of strings. Returns a string representation of the “deep contents” of the specified array. Adding New Elements on the Fly. Arrays are useful and fundamental structures that exist in every high-level language. Or better yet just just translate the 2D index into a linear index mathematically. View the specification chart to find your ideal combination. I have two for loops and two counters to determine the size of the array and then copy the multidimensional array's values into the 1D array, but it only prints out the first half of the array as such:. It works because of autoboxing and char ‘P’ is being converted to 80 in the byte array. Viewed 8k times 2 $\begingroup$ I have a 3D matrix like this:. I too would like answers to these questions. Two-dimensional Arrays Daniel Shiffman. The value of those indices must be the same value, in. opengles and javax. An array keeps track of multiple pieces of information in linear order, a one-dimensional list. When working with 2D arrays (matrices), row-major vs. A cell array is a data type with indexed data containers called cells, where each cell can contain any type of data. You can think this array as table with 3 rows and each row has 4 columns as shown below. By continuing to browse this site, you agree to this use. The array will have shape (width, height, (b,g,r,a)). The zyBooks Approach Less text doesn’t mean less learning. I'm trying to create a gear by drawing a circle and a single tooth for a gear, then using a polar array to create teeth around the circle. 2 NaN 2 NaN NaN 0. The 3D array is then converted into a surface or set of surfaces using isosurface extraction techniques. I think, almost all of NCAR data like OLR is 3D array format, but in nc file, how to produce it for text file or binary file using ncl language ?. Topographic surface from 2D geographic data sets 3D data volumes may be sliced in the X, Y, or Z plane using an interactive cutting plane. In the code below, the function "flatten" is supposed to take a 2 x 2 array and "flatten" it into a one-dimensional vector. We'll see more detailed explanations later. But a more important question here is why you need to do this at all. Printing array values in Java or values of array element in Java would have been much easier if arrays are allowed to directly prints its values whenever used inside System. For any n-dimensional rotation matrix R acting on ℝ n,. may_share_memory() to check if two arrays share the same memory block. Thus the original array is not copied in memory. Multidimensional Arrays (C# Programming Guide) 07/20/2015; 2 minutes to read +3; In this article. sortInPlaceBy, and Array. Learn more about logical_indexing. please introduse me some good source or if there is an open source. solution for 3D human-computer interaction based on RFID, by simply attaching a linear RFID tag array onto the linear shaped object like a brush. Toggle Main Navigation. In case you want to create 2D numpy array or a matrix, simply pass python list of list to np. In this post we see what is the solution to the problem of adding a new element to an existing array. reshape(16,16) #16x16 array [/code]I suppose you might not want to be using the Numpy ecosystem completely. And both rows and columns combine to make two-dimensional (2D) Arrays. Converting from 2D to 1D is easy, since you just concatenate all values. In Perl each element of an array can be a reference to another array, but syntactically they would look like a two-dimensional array. In the code below, the function "flatten" is supposed to take a 2 x 2 array and "flatten" it into a one-dimensional vector. That is, is it laid out as (3x101) x 406, or as (101x3) x 406?. Default is 0. SA, sorry if I in some way hurt you. A slicing operation creates a view on the original array, which is just a way of accessing array data. String also has a constructor where we can provide byte array and Charset as an argument. As in the single GPU case, cufftEstimateSize{Many,1d,2d,3d}() and cufftGetSize{Many,1d,2d,3d}() give estimates of the work area sizes required for a multiple GPU plan and in this case workSize points to a size_t array, one entry per GPU. seems like you want a 2D array. I use mvrnorm to create all the. So when you run your outer loop, you get array elements which are in between {} first deep level brackets. Hi, Hope someone can help, I have a 2D array of 1062 x 300 doubles in the format of Xn Yn Zn and I am trying to convert it into a 1062 x 100 x 3 matrix where each of the 3 dimensional points are collected together. I have recently become quite obsessed with 3D design and printing, thanks to OpenSCAD that made designing 3D objects just too easy not to try, if you want to make 3D models from an image or SVG file, you can do it very easily – there are other ways to convert to other 3D formats,. I know you can do this fairly simply with a Named Range (set myArray = [insert named range]), however when trying to do this with a table I am running into some difficulty. Or better yet just just translate the 2D index into a linear index mathematically.