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

Suggested way to add a column #9

Closed
ben-ng opened this issue Jul 24, 2014 · 2 comments
Closed

Suggested way to add a column #9

ben-ng opened this issue Jul 24, 2014 · 2 comments

Comments

@ben-ng
Copy link

ben-ng commented Jul 24, 2014

Hey Mikola, do you know of a fast way to add a column to a 2d array?

This is just a shot in the dark; I have a feeling that I need to allocate a new typed array to achieve this.

@rreusser
Copy link
Member

rreusser commented Jan 7, 2016

@ben-ng: this is ridiculously late, but I've added ndarray-concat-rows and ndarray-concat-cols to merge arrays. It includes the option to let it allocate new storage. It's not exactly what you want(ed), but it's in the ballpark.

See also: ndarray-concat-cols in the scijs docs

@rreusser
Copy link
Member

rreusser commented Jan 7, 2016

Though to answer your specific question, there's no truly fast way, in general. There are cases where you could just extend the data array and that would be the last column, but it may also be the case that it's transposed and the new column is staggered throughout the data. So to answer the question, yes, I think in general at least, you need to allocate a new array.

For the case where the new column is contiguous, if you used a plain Array, it'd just expand to accommodate the new entries if you messed with the stride, shape, and offset, but since that's not generally applicable, I'll close this in favor of the above solutions and just having to do it manually sometimes, if that's alright.

Oh, and in case you weren't onto totally different stuff a year and a half ago already, see also: scijs-ndarray-for-matlab-users

@rreusser rreusser closed this as completed Jan 7, 2016
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