Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getter example #16

Open
matthewmueller opened this issue Apr 9, 2015 · 1 comment
Open

Getter example #16

matthewmueller opened this issue Apr 9, 2015 · 1 comment

Comments

@matthewmueller
Copy link

It wasn't immediately obvious how to actually loop over this array from the examples. Something like this would be helpful to newcomers:

var mat = ndarray([1, 2, 3, 4, 5, 6, 7, 8, 9], [3,3])
var m = mat.hi(2, 2)

console.log('at: %s', m.get(2, 2));
for(var i=0; i < m.shape[0]; ++i) {
  for(var j=0; j < m.shape[1]; ++j) {
    console.log('(%s, %s): %s', i, j + m.offset, mat.get(i, j + m.offset));
  }
}

I can open a PR to add it to the Readme, if you're interested, or if there's a better way to improve this, so it's more generic.

@mikolalysenko
Copy link
Member

Looks good to me! If you want to write something I will merge it in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants