Suggestion #19
Comments
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. |
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. |
Hm, that's probably what NumPy means by ndarray. I took it different: an N dimensional vector is one with N components. |
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. |
For reference: http://docs.scipy.org/doc/numpy-1.10.0/reference/arrays.ndarray.html |
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:
|
Is it possible to represent 3D structures in swix? |
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:
|
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. |
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:
|
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? |
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:
|
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. |
This use case is already covered... It'd be more to provide NumPy similarity. |
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.The text was updated successfully, but these errors were encountered: