0

I need to create an empty nd-array in python without zeros or ones functions looks like in c++ with this command for array 3*4 for integers:

int x[3][4]

Please help me

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Arash Moh
  • 1
  • 2
  • 2
    Why do you say 'without zeros or ones'? – matt Nov 04 '19 at 19:49
  • 1
    What do you mean by "empty"? In numpy, usually empty means "one or more of the dimensions has extent 0". If you really mean it should have dimensions 3x4, then `zeros` or `ones` is the way to go. It would be unusual in numpy to allocate an array without initializing the content—but as I have *just* this second learned from matt's comment, there is a function `empty` that will do it. – jez Nov 04 '19 at 19:50
  • 1
    https://docs.scipy.org/doc/numpy/reference/generated/numpy.empty.html#numpy.empty – matt Nov 04 '19 at 19:51
  • because maybe i need to create char array so i need to change the type or maybe 0 was an important number in the array or any thing else. – Arash Moh Nov 04 '19 at 19:52
  • 1
    Both of those reasons are somewhat incorrect. If 0 is important, than you don't want an array of random values. Even c++ will initialize arrays depending on compiler options. So if you have a special value you should initialize the array to a set of valid values. Also, changing the type seems irrelevant to whether or not it was initialized. – matt Nov 04 '19 at 19:56
  • 1
    If you don't like `empty()`, try `full()`. That lets you specify the initial value. – jez Nov 04 '19 at 19:57
  • thanks a lot. empty and full is ok for me. – Arash Moh Nov 04 '19 at 20:53

1 Answers1

2

Numpy has a function for that. empty

matt
  • 10,892
  • 3
  • 22
  • 34