2

Currently, I have this piece of code to create a numpy array

X=np.array([[]]);

if (X.shape[1] == 0):
      X = np.array([vd]);
    else:
      X = np.concatenate((X,np.array([vd])));

I would now like to get multiple numpy arrays X(1) , X(2) etc for different conditions. What is the best way to do this in python. In matlab I can accomplish this using matlab struct.

2 Answers 2

1

You can use a python dictionary for this purpose For example

import numpy as np
dic={}
dic['1']=np.zeros(3)
dic['2']=np.ones(5)
print dic['1']
print dic['2']

now dic['1'] and dic['2'] are you arrays

Sign up to request clarification or add additional context in comments.

2 Comments

can it be dic[1]=np.zeros(3) ?
Yes, it can be like that as well
0

I see @user3510686 has already answered it. Posing what I tried.

a={}
for i in range(10):
    a[i]=np.random.rand(10)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.