Home > Software design >  Python fill an array with a specific array
Python fill an array with a specific array

Time:08-04

I am going to fill an array in Python, but I couldn't find a good solution. I am trying to convert a MatLab code like this:

data_ax( : , 1:n ) = df( : , 1 n [1:n] );

and n could be 1, 2, or 3.

data_ax is [200 X 1]

df is [200 X 7]

Thank you.

CodePudding user response:

If your MATLAB code is correct, this is the equivalent Python one using NumPy.

import numpy as np

df = np.random.rand(200,7)

n = 2
data_ax = df[:, n 1:2*n 1]

Or,

data_ax = df[:, 1 n np.arange(0,n)]
  • Related