Skip to content
This repository has been archived by the owner on Jul 26, 2020. It is now read-only.

Suggestion #19

Closed
seewalker opened this issue Dec 26, 2015 · 14 comments
Closed

Suggestion #19

seewalker opened this issue Dec 26, 2015 · 14 comments

Comments

@seewalker
Copy link

This is a very cool project. I'm wondering if there is any interest in adding a shape attribute of ndarrays? I see there is some interest (for good reason) in being similar to numpy/matlab, and the program I'm writing makes its own shape variables for ndarrays. I'd make a pull request if project maintainers believe it would be a desirable and straightforward change.

@stsievert
Copy link
Owner

Yes, adding a shape attribute to ndarrays would be good and straightforward. As with NumPy, it should probably return the Swift equivalent of a tuple.

@lucasderraugh
Copy link

Is the ndarray in Swix actually an n-dimensional array? If I'm interpreting the library correctly, you need to use the matrix to create a 2D representation.

@stsievert
Copy link
Owner

Hm, that's probably what NumPy means by ndarray. I took it different: an N dimensional vector is one with N components.

@lucasderraugh
Copy link

I think in NumPy you could represent something in 3D and shape would give you the shape would yield the size for 3 dimensions. I only ask because I'm not sure how shape would be useful in the way swix currently works.

@lucasderraugh
Copy link

For reference: http://docs.scipy.org/doc/numpy-1.10.0/reference/arrays.ndarray.html
They give an example of a 2D array with size 2x3, which is when shape yields the tuple (2, 3). Not sure how you could represent the same thing in Swift though (is it possible to return a variable number tuple).

@stsievert
Copy link
Owner

Exactly correct. In NumPy, the shape of an ndarray or N-dimensional array returns a tuple with N elements. In swix notation, an ndarray .shape should return a tuple (or Swift equivalent) with one element. matrix.shape should return a tuple with two elements.

On Jan 10, 2016, 8:48 PM -0600, Lucas Derraughnotifications@github.com, wrote:

For reference:http://docs.scipy.org/doc/numpy-1.10.0/reference/arrays.ndarray.html
They give an example of a 2D array with size 2x3, which is when shape yields the tuple (2, 3). Not sure how you could represent the same thing in Swift though (is it possible to return a variable number tuple).


Reply to this email directly orview it on GitHub(#19 (comment)).

@lucasderraugh
Copy link

Is it possible to represent 3D structures in swix?

@stsievert
Copy link
Owner

No. When making this library, I knew that vectors and matrices were most commonly used, at least in DSP/etc and didn't have the experience to expand this to N dimensions (as opposed to 1 or 2).

On Jan 10, 2016, 9:02 PM -0600, Lucas Derraughnotifications@github.com, wrote:

Is it possible to represent 3D structures in swix?


Reply to this email directly orview it on GitHub(#19 (comment)).

@lucasderraugh
Copy link

I don't know many use cases either, but I have used more than 2 dimensions on some projects. Regardless, really cool library! Not sure if expanding this to n dimensions would be a goal at all. Even if we tried to expand it, I'm not sure if Swift's type system would be too strict to make n dimensions work easily.

@stsievert
Copy link
Owner

Exactly my thoughts. Did we address your suggestion about shapes?

Thinking about this, at the core of it NumPy probably has a list of numbers where every Nth number represents one of the N dimensions. That means element wise operations are straightforward... But I'll leave it on paper (implementation is probably tricky).

On Jan 10, 2016, 9:12 PM -0600, Lucas Derraughnotifications@github.com, wrote:

I don't know many use cases either, but I have used more than 2 dimensions on some projects. Regardless, really cool library! Not sure if expanding this to n dimensions would be a goal at all. Even if we tried to expand it, I'm not sure if Swift's type system would be too strict to make n dimensions work easily.


Reply to this email directly orview it on GitHub(#19 (comment)).

@lucasderraugh
Copy link

Forgive the ignorance, but I don't think I understand what the shape proposal would be. If ndarray is currently just an array with n elements essentially, isn't shape just the equivalent of the count?

@stsievert
Copy link
Owner

Yup, exactly. Well, shape wraps it in a one-element tuple. For a 1D array, NumPy says "x.shape == (n,)".

No worries on ignorance -- asking questions is useful and positive! I have strong feelings and many more words say about this.

On Jan 10, 2016, 9:26 PM -0600, Lucas Derraughnotifications@github.com, wrote:

Forgive the ignorance, but I don't think I understand what the shape proposal would be. If ndarray is currently just an array with n elements essentially, isn't shape just the equivalent of the count?


Reply to this email directly orview it on GitHub(#19 (comment)).

@lucasderraugh
Copy link

Ya, I guess the question is just if the type is either 1D array (ndarray) or 2D array (matrix), what is the use case for shape? I think the (n,) syntax is simply used because shape returns a tuple, and tuples in python have to have at least 2 elements to make it a tuple.

@stsievert
Copy link
Owner

This use case is already covered... It'd be more to provide NumPy similarity.

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

No branches or pull requests

3 participants