Created
April 7, 2019 05:21
-
-
Save singularitti/0fad2f4e5535dc60333e5647b0b13b7e to your computer and use it in GitHub Desktop.
Meshgrid on 2D #JavaScript #array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function meshgrid(xArray, yArray) { | |
| /* | |
| Here xArray, yArray should all be 1d arrays. | |
| Then it returns 2 fortran-style 2D arrays, that is, | |
| they are all column-major order: | |
| http://www.wikiwand.com/en/Row-_and_column-major_order. | |
| The returned xMesh and yMesh are all of shape [xNum, yNum]. | |
| */ | |
| let xNum = xArray.size; | |
| let yNum = yArray.size; | |
| let xMesh = reshape(tile(xArray, [yNum]), [xNum, yNum]); | |
| let yMesh = reshape(tile(yArray, [1, xNum]).transpose(1, 0), [xNum, yNum]); | |
| return [xMesh, yMesh]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment