![](https://secure.gravatar.com/avatar/afbfea54f96c24ee538542fcbf10b260.jpg?s=120&d=mm&r=g)
hello, sorry newbe to numpy. I want to define a three-dim array. I know this works:
[[5, 6], [7, 8]]]) But can you tell why this doesnt work?
Thank you.
![](https://secure.gravatar.com/avatar/5d8caeb7bf0e4b29cc75a5f5646b0db3.jpg?s=120&d=mm&r=g)
I believe numpy arrays must be rectangular, yours is jagged, instead try
Note: 3 opening brackets, yours has 2 And single brackets around the 3 innermost arrays, yours has single brackets for the 1st, and double brackets around the 2nd and 3rd On Tue, Dec 25, 2018, 6:20 PM Jeff <jeffp@vodafonemail.de wrote:
![](https://secure.gravatar.com/avatar/209654202cde8ec709dee0a4d23c717d.jpg?s=120&d=mm&r=g)
In the latest version of numpy, this runs without an error, although may or may not be what you want: In [1]: np.array([[1,2],[[1,2],[3,4]]]) Out[1]: array([[1, 2], [list([1, 2]), list([3, 4])]], dtype=object) Here the result is a 2x2 array, where some elements are numbers and others are lists. On Wed, 26 Dec 2018 at 06:23 Mark Alexander Mikofski <mikofski@berkeley.edu> wrote:
![](https://secure.gravatar.com/avatar/209654202cde8ec709dee0a4d23c717d.jpg?s=120&d=mm&r=g)
The rationale for the change allowing that construction was twofold: it's easier to understand what has gone wrong when seeing the `list`s in the repr than it was from the cryptic error message; and there were some jagged cases that already succeeded in this way, and it was less confusing to be consistent. I agree that the behavior is not terribly useful, and object arrays constructed containing lists are quite possibly something we should warn about. Eric On Thu, Dec 27, 2018, 2:22 AM Benjamin Root <ben.v.root@gmail.com wrote:
![](https://secure.gravatar.com/avatar/851ff10fbb1363b7d6111ac60194cc1c.jpg?s=120&d=mm&r=g)
There is a long-standing request to require an explicit opt-in for dtype=object: https://github.com/numpy/numpy/issues/5353 -- Marten
![](https://secure.gravatar.com/avatar/5d8caeb7bf0e4b29cc75a5f5646b0db3.jpg?s=120&d=mm&r=g)
I believe numpy arrays must be rectangular, yours is jagged, instead try
Note: 3 opening brackets, yours has 2 And single brackets around the 3 innermost arrays, yours has single brackets for the 1st, and double brackets around the 2nd and 3rd On Tue, Dec 25, 2018, 6:20 PM Jeff <jeffp@vodafonemail.de wrote:
![](https://secure.gravatar.com/avatar/209654202cde8ec709dee0a4d23c717d.jpg?s=120&d=mm&r=g)
In the latest version of numpy, this runs without an error, although may or may not be what you want: In [1]: np.array([[1,2],[[1,2],[3,4]]]) Out[1]: array([[1, 2], [list([1, 2]), list([3, 4])]], dtype=object) Here the result is a 2x2 array, where some elements are numbers and others are lists. On Wed, 26 Dec 2018 at 06:23 Mark Alexander Mikofski <mikofski@berkeley.edu> wrote:
![](https://secure.gravatar.com/avatar/209654202cde8ec709dee0a4d23c717d.jpg?s=120&d=mm&r=g)
The rationale for the change allowing that construction was twofold: it's easier to understand what has gone wrong when seeing the `list`s in the repr than it was from the cryptic error message; and there were some jagged cases that already succeeded in this way, and it was less confusing to be consistent. I agree that the behavior is not terribly useful, and object arrays constructed containing lists are quite possibly something we should warn about. Eric On Thu, Dec 27, 2018, 2:22 AM Benjamin Root <ben.v.root@gmail.com wrote:
![](https://secure.gravatar.com/avatar/851ff10fbb1363b7d6111ac60194cc1c.jpg?s=120&d=mm&r=g)
There is a long-standing request to require an explicit opt-in for dtype=object: https://github.com/numpy/numpy/issues/5353 -- Marten
participants (6)
-
Benjamin Root
-
Eric Wieser
-
Jeff
-
Mark Alexander Mikofski
-
Marten van Kerkwijk
-
Matti Picus