0

data is a 1256x277 matrix

np.array_split(ary=data, indices_or_sections=10, axis=1) gives us a list of 1256x28 data

But when I do:

sub_data_ndarray = np.array(object=np.array_split(ary=data, indices_or_sections=10, axis=1))

I get the error:

ValueError: could not broadcast input array from shape (1256,28) into shape (1256)

?

NoName
  • 9,824
  • 5
  • 32
  • 52
  • Check that all the arrays produced by `np.array_splt` have the same shape. – hpaulj Jul 22 '20 at 18:29
  • @hpaulj The result is seven 1256x28 matrix and three 1256x27 matrix. – NoName Jul 22 '20 at 18:37
  • Then you can't reassemble them into one 3d array. – hpaulj Jul 22 '20 at 18:41
  • @hpaulj hmmm but I'm not trying to. I want to convert the resulting list [sub_data, sub_data, sub_data] into a ndarray so I can use ndarray selection operations. And those sub_data just happens to be a matrix. – NoName Jul 22 '20 at 18:44
  • What kind of `ndarray selection operations` do you have in mind? At best you can make an object dtype array. I could show you how to do that, but ... – hpaulj Jul 22 '20 at 19:38
  • https://stackoverflow.com/q/62994636/901925 – hpaulj Jul 22 '20 at 20:01

1 Answers1

0

try with np.stack:

A = [1,2,3,4,5,6,7,8,9,0]
B = [1,2,3,4,5,6,7,8,9,0]
C = np.stack((A, B))
Dorian
  • 1,439
  • 1
  • 11
  • 26
  • `np.array((A,B))` works with your lists just as well. I expect `stack` will have problems with the OP's list as well, though it will give a different (and possibly clearer) error message. – hpaulj Jul 22 '20 at 18:31