0

I wont create a matrix of matrix with numpy.array, this matrix only need two elements, the comand is:

numpy.array([m1,m2])

this work fine indpendently of the matrices size, except when a matrix have a dimension in one. Example:

m1 = numpy.ones((2,2))
m2 = numpy.ones((2,1))
numpy.array([m1,m2])

In this case show error... and the shape for the matrices are (2,2) and (2,1) but for some reason i think that the dimension 1 is the problem. Someone know as fix this problem. Thanks!

3
  • The arrays differ in size, so it can't make a neat 3d array. If the arrays differ in the first dimension it can make a (2,) shape object dtype array. But with the same 1st dimension, np.array throws an error. Maybe you shouldn't be creating such an array! Commented Dec 10, 2019 at 23:15
  • What exactly are you expecting? Can you get there without using np.array? Remember, an object dtype array is little better than a list, and in some ways, worse. Commented Dec 10, 2019 at 23:19
  • Another way to phrase this - np.array([m1,m2]) is an unreliable way of making a (2,) shape object dtype array. Better M=np.empty(2, object) and M[0]=m1 and M[1]=m2 (or some variation on that). Commented Dec 10, 2019 at 23:35

1 Answer 1

1

This appears to be a known bug, or maybe just an undesirable behavior in numpy.

https://github.com/numpy/numpy/issues/7453

I would definitely question why this particular arrangement is appealing, though.
Obv not for the matrix arithmetic operations, since your arrays are of varying nth-dimension.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.