-1

I would like to create an numpy array like the one below, except I want to be able to create a variable shape array. So for the one below it would be n=3. Is there an a slick way to do this with numpy, or do I need a for loop.

output data:

import numpy as np

np.array([1,0,0],[0,1,0],[0,0,1],[1,1,1],[0,0,0])
Sociopath
  • 13,068
  • 19
  • 47
  • 75
modLmakur
  • 531
  • 2
  • 8
  • 24

1 Answers1

0

Say you want to create array with name d having row number of rows and col number of columns. It would also initialize all elements of the array with 0.

d = [[0 for x in range(col)] for y in range(row)]

You can access any element I,j by d[i][j].

taurus05
  • 2,491
  • 15
  • 28
Neha
  • 1
  • The OP hasn't mentioned that there are `row` number of rows and `col` number of columns. – taurus05 Feb 05 '19 at 06:43
  • sorry I don't think I worded this very well but I also think I found the answer in another post https://stackoverflow.com/questions/14931769/how-to-get-all-combination-of-n-binary-value – modLmakur Feb 06 '19 at 05:06