0

I'm trying to create a list of 3x3 matrices; but the initialization isn't working. Just wondering what I'm doing wrong. Managed to isolate the error in a 2-line program.

import numpy as np
delta=[np.empty(3,3) for i in range(1023)]

I get TypeError: data type not understood. What went wrong and what's the right way to do this?

Thanks

J.D.
  • 139
  • 4
  • 14
  • Possible duplicate of [How do I create an empty array/matrix in NumPy?](https://stackoverflow.com/questions/568962/how-do-i-create-an-empty-array-matrix-in-numpy) – Diptangsu Goswami Sep 06 '19 at 04:13

2 Answers2

0

Try this:

delta = [
    np.zeros([3, 3], dtype=int)
    for _ in range(1023)
]
Diptangsu Goswami
  • 5,554
  • 3
  • 25
  • 36
  • Thanks, that worked. Result is kind of strange though as the matrices created aren't actually empty, but have numbers filled in. – J.D. Sep 06 '19 at 04:55
0

np.empty() Return a new array of given shape and type, without initializing entries.

numpy.empty(shape, dtype=float, order='C')

order : {‘C’, ‘F’}, optional, default: ‘C’ Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory.

we have to give matrix formate in [] braces example:

x=[np.empty([3,3],dtype=int,order='F') for i in range(1023)]