Python Forum
Python 2 dimensional array creations
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python 2 dimensional array creations
#1
I'm attempting to create my first 2 dimensional array. But I'm not getting the anticipated results:
import numpy as np
a = [[11,12,13],[21.22,23],[31,32,33]] # nested list
x = np.array(a)  # cast into an array
x
My Results:
array([list([11, 12, 13]), list([21.22, 23]), list([31, 32, 33])],
dtype=object)


I'm expecting x.ndim to return 2 since it's a List containing 3 other Lists, but it's only returning 1.

I'm expecting x.shape to return (3,3,), but instead it's returning (3,)

Any help would be greatly appreciated.
Reply
#2
There is a typo in your list a, take a careful look on every character!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to quantize a 4 dimensional array? PythonNPC 2 1,612 Apr-23-2022, 04:34 PM
Last Post: Gribouillis
  How to create 2 dimensional variables in Python? plumberpy 5 1,848 Mar-31-2022, 03:15 AM
Last Post: plumberpy
  Slicing a 2 dimensional array Scott 2 1,650 Jan-12-2022, 07:18 AM
Last Post: paul18fr
  Problem using two-dimensional interpolation. Result looks bad player1682 4 2,504 Oct-12-2021, 09:27 AM
Last Post: player1682
  Index data must be 1-dimensional : Classifier with sklearn Salma 0 4,311 Apr-01-2021, 03:22 PM
Last Post: Salma
  2 Dimensional Arrays Prithak 4 2,590 Mar-21-2021, 09:35 PM
Last Post: deanhystad
  Indexing [::-1] to Reverse ALL 2D Array Rows, ALL 3D, 4D Array Columns & Rows Python Jeremy7 8 7,105 Mar-02-2021, 01:54 AM
Last Post: Jeremy7
  comparing 2 dimensional list glennford49 10 4,130 Mar-24-2020, 05:23 PM
Last Post: saikiran
  Python: Creating N Dimensional Grid jf451 0 2,319 Dec-06-2018, 10:53 PM
Last Post: jf451
  Get last tuple from two-dimensional array? Winfried 6 3,851 Aug-27-2018, 01:48 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020