Home > Software engineering >  how do I convert this java 2d array to python
how do I convert this java 2d array to python

Time:05-19

I have this 2d array in java

    String[][] Orders = new String[5000][7];

How do I create this in empty 2d array of strings in python?

I have tried

    Orders = [[]]

But when I go to put a value in it I get an index array out of bounds error

    Orders[0][0] = 'foo'
    Orders[0][1] = 'boo'

CodePudding user response:

my_rows, my_cols = (3, 4)
my_array = [[0]*my_cols]*my_rows
print(my_array)

Link for reference https://pythonguides.com/create-an-empty-array-in-python/#:~:text=Create empty array Python,-In python, we&text=Create a list [0] and,will get an empty array.

edit: After further research multidimensional arrays do not seem as feasible in python as they are in Java

Here is a previous post on the topic: Two dimensional array in python

CodePudding user response:

here how to use pandas to, pandas is a libary from python that help you with data

  • Related