Discussion:
[Numpy-discussion] Multi-dimensional array of splitted array
Ibrahim EL MEREHBI
2016-03-23 13:06:44 UTC
Permalink
Hello,

I have a multi-diensional array that I would like to split its columns.

For example consider,

dat = np.array([np.arange(10),np.arange(10,20), np.arange(20,30)]).T

array([[ 0, 10, 20],
[ 1, 11, 21],
[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24],
[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27],
[ 8, 18, 28],
[ 9, 19, 29]])


I already can split one column at a time:

np.array_split(dat[:,0], [2,5,8])

[array([0, 1]), array([2, 3, 4]), array([5, 6, 7]), array([8, 9])]


How can I extend this for all columns and (overwrite or) have a new
multi-dimensional array?

Thank you,
Bob
Eric Moore
2016-03-23 13:17:35 UTC
Permalink
Try just calling np.array_split on the full 2D array. It splits along a
particular axis, which is selected using the axis argument of
np.array_split. The axis to split along defaults to the first so the two
calls to np.array_split below are exactly equivalent.

In [16]: a = np.c_[:10,10:20,20:30]


In [17]: np.array_split(a, [2,5,8])

Out[17]:

[array([[ 0, 10, 20],

[ 1, 11, 21]]), array([[ 2, 12, 22],

[ 3, 13, 23],

[ 4, 14, 24]]), array([[ 5, 15, 25],

[ 6, 16, 26],

[ 7, 17, 27]]), array([[ 8, 18, 28],

[ 9, 19, 29]])]


In [18]: np.array_split(a, [2,5,8], 0)

Out[18]:

[array([[ 0, 10, 20],

[ 1, 11, 21]]), array([[ 2, 12, 22],

[ 3, 13, 23],

[ 4, 14, 24]]), array([[ 5, 15, 25],

[ 6, 16, 26],

[ 7, 17, 27]]), array([[ 8, 18, 28],

[ 9, 19, 29]])]


Eric
Post by Ibrahim EL MEREHBI
Hello,
I have a multi-diensional array that I would like to split its columns.
For example consider,
dat = np.array([np.arange(10),np.arange(10,20), np.arange(20,30)]).T
array([[ 0, 10, 20],
[ 1, 11, 21],
[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24],
[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27],
[ 8, 18, 28],
[ 9, 19, 29]])
np.array_split(dat[:,0], [2,5,8])
[array([0, 1]), array([2, 3, 4]), array([5, 6, 7]), array([8, 9])]
How can I extend this for all columns and (overwrite or) have a new
multi-dimensional array?
Thank you,
Bob
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
Ibrahim EL MEREHBI
2016-03-23 13:37:48 UTC
Permalink
Thanks Eric. I already checked that. It's not what I want. I think I
wasn't clear about what I wanted.

I want to split each column but I want to do it for each column and end
up with an array. Here's the result I wish to have:

array([[[0], [1, 2, 3, 4], [5, 6, 7], [8, 9]],
[[10], [11, 12, 13, 14], [15, 16, 17], [18, 19]],
[[20], [21, 21, 23, 24], [25, 26, 27], [28, 29]]], dtype=object)


Sincerely Yours,
Bob
Post by Eric Moore
Try just calling np.array_split on the full 2D array. It splits along
a particular axis, which is selected using the axis argument of
np.array_split. The axis to split along defaults to the first so the
two calls to np.array_split below are exactly equivalent.
In [16]: a = np.c_[:10,10:20,20:30]
In [17]: np.array_split(a, [2,5,8])
[array([[ 0, 10, 20],
[ 1, 11, 21]]), array([[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24]]), array([[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27]]), array([[ 8, 18, 28],
[ 9, 19, 29]])]
In [18]: np.array_split(a, [2,5,8], 0)
[array([[ 0, 10, 20],
[ 1, 11, 21]]), array([[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24]]), array([[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27]]), array([[ 8, 18, 28],
[ 9, 19, 29]])]
Eric
On Wed, Mar 23, 2016 at 9:06 AM, Ibrahim EL MEREHBI
Hello,
I have a multi-diensional array that I would like to split its columns.
For example consider,
dat = np.array([np.arange(10),np.arange(10,20), np.arange(20,30)]).T
array([[ 0, 10, 20],
[ 1, 11, 21],
[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24],
[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27],
[ 8, 18, 28],
[ 9, 19, 29]])
np.array_split(dat[:,0], [2,5,8])
[array([0, 1]), array([2, 3, 4]), array([5, 6, 7]), array([8, 9])]
How can I extend this for all columns and (overwrite or) have a
new multi-dimensional array?
Thank you,
Bob
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
Joseph Fox-Rabinovitz
2016-03-23 14:02:38 UTC
Permalink
On Wed, Mar 23, 2016 at 9:37 AM, Ibrahim EL MEREHBI
Thanks Eric. I already checked that. It's not what I want. I think I wasn't
clear about what I wanted.
I want to split each column but I want to do it for each column and end up
array([[[0], [1, 2, 3, 4], [5, 6, 7], [8, 9]],
[[10], [11, 12, 13, 14], [15, 16, 17], [18, 19]],
[[20], [21, 21, 23, 24], [25, 26, 27], [28, 29]]], dtype=object)
Apply [`np.stack`](http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.stack.html#numpy.stack)
to the result. It will merge the arrays the way you want.

-Joe
Sincerely Yours,
Bob
Try just calling np.array_split on the full 2D array. It splits along a
particular axis, which is selected using the axis argument of
np.array_split. The axis to split along defaults to the first so the two
calls to np.array_split below are exactly equivalent.
In [16]: a = np.c_[:10,10:20,20:30]
In [17]: np.array_split(a, [2,5,8])
[array([[ 0, 10, 20],
[ 1, 11, 21]]), array([[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24]]), array([[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27]]), array([[ 8, 18, 28],
[ 9, 19, 29]])]
In [18]: np.array_split(a, [2,5,8], 0)
[array([[ 0, 10, 20],
[ 1, 11, 21]]), array([[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24]]), array([[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27]]), array([[ 8, 18, 28],
[ 9, 19, 29]])]
Eric
Post by Ibrahim EL MEREHBI
Hello,
I have a multi-diensional array that I would like to split its columns.
For example consider,
dat = np.array([np.arange(10),np.arange(10,20), np.arange(20,30)]).T
array([[ 0, 10, 20],
[ 1, 11, 21],
[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24],
[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27],
[ 8, 18, 28],
[ 9, 19, 29]])
np.array_split(dat[:,0], [2,5,8])
[array([0, 1]), array([2, 3, 4]), array([5, 6, 7]), array([8, 9])]
How can I extend this for all columns and (overwrite or) have a new
multi-dimensional array?
Thank you,
Bob
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
Sebastian Berg
2016-03-23 14:21:57 UTC
Permalink
Post by Joseph Fox-Rabinovitz
On Wed, Mar 23, 2016 at 9:37 AM, Ibrahim EL MEREHBI
Thanks Eric. I already checked that. It's not what I want. I think I wasn't
clear about what I wanted.
I want to split each column but I want to do it for each column and end up
array([[[0], [1, 2, 3, 4], [5, 6, 7], [8, 9]],
[[10], [11, 12, 13, 14], [15, 16, 17], [18, 19]],
[[20], [21, 21, 23, 24], [25, 26, 27], [28, 29]]],
dtype=object)
Apply [`np.stack`](http://docs.scipy.org/doc/numpy-1.10.0/reference/g
enerated/numpy.stack.html#numpy.stack)
to the result. It will merge the arrays the way you want.
It is simply impossible to stack those arrays like he wants, it is not
a valid array.

- Sebastian
Post by Joseph Fox-Rabinovitz
-Joe
Sincerely Yours,
Bob
Try just calling np.array_split on the full 2D array. It splits along a
particular axis, which is selected using the axis argument of
np.array_split. The axis to split along defaults to the first so the two
calls to np.array_split below are exactly equivalent.
In [16]: a = np.c_[:10,10:20,20:30]
In [17]: np.array_split(a, [2,5,8])
[array([[ 0, 10, 20],
[ 1, 11, 21]]), array([[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24]]), array([[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27]]), array([[ 8, 18, 28],
[ 9, 19, 29]])]
In [18]: np.array_split(a, [2,5,8], 0)
[array([[ 0, 10, 20],
[ 1, 11, 21]]), array([[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24]]), array([[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27]]), array([[ 8, 18, 28],
[ 9, 19, 29]])]
Eric
On Wed, Mar 23, 2016 at 9:06 AM, Ibrahim EL MEREHBI <
Post by Ibrahim EL MEREHBI
Hello,
I have a multi-diensional array that I would like to split its columns.
For example consider,
dat = np.array([np.arange(10),np.arange(10,20),
np.arange(20,30)]).T
array([[ 0, 10, 20],
[ 1, 11, 21],
[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24],
[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27],
[ 8, 18, 28],
[ 9, 19, 29]])
np.array_split(dat[:,0], [2,5,8])
[array([0, 1]), array([2, 3, 4]), array([5, 6, 7]), array([8, 9])]
How can I extend this for all columns and (overwrite or) have a new
multi-dimensional array?
Thank you,
Bob
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
Sebastian Berg
2016-03-23 14:22:39 UTC
Permalink
Post by Joseph Fox-Rabinovitz
On Wed, Mar 23, 2016 at 9:37 AM, Ibrahim EL MEREHBI
Thanks Eric. I already checked that. It's not what I want. I think I wasn't
clear about what I wanted.
I want to split each column but I want to do it for each column and end up
array([[[0], [1, 2, 3, 4], [5, 6, 7], [8, 9]],
[[10], [11, 12, 13, 14], [15, 16, 17], [18, 19]],
[[20], [21, 21, 23, 24], [25, 26, 27], [28, 29]]],
dtype=object)
Apply [`np.stack`](http://docs.scipy.org/doc/numpy-1.10.0/reference/g
enerated/numpy.stack.html#numpy.stack)
to the result. It will merge the arrays the way you want.
Oh sorry, nvm. As an object array, it works of course....
Post by Joseph Fox-Rabinovitz
-Joe
Sincerely Yours,
Bob
Try just calling np.array_split on the full 2D array. It splits along a
particular axis, which is selected using the axis argument of
np.array_split. The axis to split along defaults to the first so the two
calls to np.array_split below are exactly equivalent.
In [16]: a = np.c_[:10,10:20,20:30]
In [17]: np.array_split(a, [2,5,8])
[array([[ 0, 10, 20],
[ 1, 11, 21]]), array([[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24]]), array([[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27]]), array([[ 8, 18, 28],
[ 9, 19, 29]])]
In [18]: np.array_split(a, [2,5,8], 0)
[array([[ 0, 10, 20],
[ 1, 11, 21]]), array([[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24]]), array([[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27]]), array([[ 8, 18, 28],
[ 9, 19, 29]])]
Eric
On Wed, Mar 23, 2016 at 9:06 AM, Ibrahim EL MEREHBI <
Post by Ibrahim EL MEREHBI
Hello,
I have a multi-diensional array that I would like to split its columns.
For example consider,
dat = np.array([np.arange(10),np.arange(10,20),
np.arange(20,30)]).T
array([[ 0, 10, 20],
[ 1, 11, 21],
[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24],
[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27],
[ 8, 18, 28],
[ 9, 19, 29]])
np.array_split(dat[:,0], [2,5,8])
[array([0, 1]), array([2, 3, 4]), array([5, 6, 7]), array([8, 9])]
How can I extend this for all columns and (overwrite or) have a new
multi-dimensional array?
Thank you,
Bob
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
Ibrahim EL MEREHBI
2016-03-23 14:38:53 UTC
Permalink
As an object, will it change how numpy operates?

Sincerely Yours,
Bob
Post by Sebastian Berg
Post by Joseph Fox-Rabinovitz
On Wed, Mar 23, 2016 at 9:37 AM, Ibrahim EL MEREHBI
Thanks Eric. I already checked that. It's not what I want. I think I wasn't
clear about what I wanted.
I want to split each column but I want to do it for each column and end up
array([[[0], [1, 2, 3, 4], [5, 6, 7], [8, 9]],
[[10], [11, 12, 13, 14], [15, 16, 17], [18, 19]],
[[20], [21, 21, 23, 24], [25, 26, 27], [28, 29]]],
dtype=object)
Apply [`np.stack`](http://docs.scipy.org/doc/numpy-1.10.0/reference/g
enerated/numpy.stack.html#numpy.stack)
to the result. It will merge the arrays the way you want.
Oh sorry, nvm. As an object array, it works of course....
Post by Joseph Fox-Rabinovitz
-Joe
Sincerely Yours,
Bob
Try just calling np.array_split on the full 2D array. It splits along a
particular axis, which is selected using the axis argument of
np.array_split. The axis to split along defaults to the first so the two
calls to np.array_split below are exactly equivalent.
In [16]: a = np.c_[:10,10:20,20:30]
In [17]: np.array_split(a, [2,5,8])
[array([[ 0, 10, 20],
[ 1, 11, 21]]), array([[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24]]), array([[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27]]), array([[ 8, 18, 28],
[ 9, 19, 29]])]
In [18]: np.array_split(a, [2,5,8], 0)
[array([[ 0, 10, 20],
[ 1, 11, 21]]), array([[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24]]), array([[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27]]), array([[ 8, 18, 28],
[ 9, 19, 29]])]
Eric
On Wed, Mar 23, 2016 at 9:06 AM, Ibrahim EL MEREHBI <
Post by Ibrahim EL MEREHBI
Hello,
I have a multi-diensional array that I would like to split its columns.
For example consider,
dat = np.array([np.arange(10),np.arange(10,20),
np.arange(20,30)]).T
array([[ 0, 10, 20],
[ 1, 11, 21],
[ 2, 12, 22],
[ 3, 13, 23],
[ 4, 14, 24],
[ 5, 15, 25],
[ 6, 16, 26],
[ 7, 17, 27],
[ 8, 18, 28],
[ 9, 19, 29]])
np.array_split(dat[:,0], [2,5,8])
[array([0, 1]), array([2, 3, 4]), array([5, 6, 7]), array([8, 9])]
How can I extend this for all columns and (overwrite or) have a new
multi-dimensional array?
Thank you,
Bob
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
Loading...