A simple question: in numpy, how do you make a multidimensional array of arrays?

Right, maybe I should use regular Python lists for this, but here goes:

I need a 9 by 4 multidimensional array / matrix (no matter what it is) that I want to store arrays in. These arrays will be one-dimensional and 4096 long.

So I want me to have something like

column = 0                                    #column to insert into
row = 7                                       #row to insert into
storageMatrix[column,row][0] = NEW_VALUE
storageMatrix[column,row][4092] = NEW_VALUE_2
etc..

I appreciate that I could do something a little stupid / unnecessary here, but it will make it easier for me to structure it this way in my code (since there are many, and many analyzes that will be done later).

Thank!

+3
source share
2 answers

, numpy 3- numpy. 3- 2- 1- numpy.

, , 3- .

, , :

import numpy as np
storageMatrix=np.empty((4,9),dtype='object')

dtype 'object', numpy, storageMatrix Python.

numpy 1-d numpy:

storageMatrix[column,row]=np.arange(4096)

:

storageMatrix[column,row][0] = 1
storageMatrix[column,row][4092] = 2
+8

NumPy , 2D- :

x = ones( (3,4) )

2D- :

>>> x[1,2] = 20
>>> x[1,:]                             # x second row
array([ 1,  1, 20,  1])
>>> x[0] = a                           # change first row of x
>>> x
array([[10, 20, -7, -3],
       [ 1,  1, 20,  1],
       [ 1,  1,  1,  1]])
0

Source: https://habr.com/ru/post/1734067/


All Articles