Skip to main content
Improved formatting
Source Link
Stephen Rauch
  • 1.8k
  • 11
  • 22
  • 34

I want to create a dataset from three numpy matrices - train1 = (204,), train2 = (204,) and train3 = (204,). Basically all sets are of same length. I am applying a sliding window function on each of window 4. Each set become of shape =(201,4) I want a new array in which all these values are appended row wise. Like for first train1 then train2 then train3. And final output set is of size =(603,4).

This

This is a slindingsliding window function which converts array of shape (204,) to (201,4)

def moving_window(x, length, step=1):
    streams = it.tee(x, length) 
    return zip(*[it.islice(stream, i, None, step) for stream, i in zip(streams, it.count(step=step))]) 

Create dataset fucntion is:

def create_dataset(dataset1,dataset2):
    dataX=[]       
    x=list(moving_window(dataset1,4))
    x=np.asarray(x) 
    dataX.append(x)
    y=list(moving_window(dataset2,4)) 
    y=np.asarray(y) 
    dataX.append(y) 
    return np.array(dataX)

data_new=create_dataset(train1,train2)

It is returning a dataset of shape 0(2,201,4). I think this is appending differently, but iI want row wise appending. so that the new _dataset is of shape= (402,4) with two sets and (603,4) with three sets. I want to generalize as well like if iI want for 10 training sets or twenty training sets.how How can iI do that. Please give valuable suggestions.?

I want to create a dataset from three numpy matrices - train1 = (204,), train2 = (204,) and train3 = (204,). Basically all sets are of same length. I am applying a sliding window function on each of window 4. Each set become of shape =(201,4) I want a new array in which all these values are appended row wise. Like for first train1 then train2 then train3. And final output set is of size =(603,4).

This is a slinding window function which converts array of shape (204,) to (201,4)

def moving_window(x, length, step=1):
    streams = it.tee(x, length) 
    return zip(*[it.islice(stream, i, None, step) for stream, i in zip(streams, it.count(step=step))]) 

Create dataset fucntion is:

def create_dataset(dataset1,dataset2):
    dataX=[]       
    x=list(moving_window(dataset1,4))
    x=np.asarray(x) 
    dataX.append(x)
    y=list(moving_window(dataset2,4)) 
    y=np.asarray(y) 
    dataX.append(y) 
    return np.array(dataX)

data_new=create_dataset(train1,train2)

It is returning a dataset of shape 0(2,201,4). I think this is appending differently, but i want row wise appending. so that the new _dataset is of shape= (402,4) with two sets and (603,4) with three sets. I want to generalize as well like if i want for 10 training sets or twenty training sets.how can i do that. Please give valuable suggestions.

I want to create a dataset from three numpy matrices - train1 = (204,), train2 = (204,) and train3 = (204,). Basically all sets are of same length. I am applying a sliding window function on each of window 4. Each set become of shape =(201,4) I want a new array in which all these values are appended row wise. Like for first train1 then train2 then train3. And final output set is of size =(603,4).

This is a sliding window function which converts array of shape (204,) to (201,4)

def moving_window(x, length, step=1):
    streams = it.tee(x, length) 
    return zip(*[it.islice(stream, i, None, step) for stream, i in zip(streams, it.count(step=step))]) 

Create dataset fucntion is:

def create_dataset(dataset1,dataset2):
    dataX=[]       
    x=list(moving_window(dataset1,4))
    x=np.asarray(x) 
    dataX.append(x)
    y=list(moving_window(dataset2,4)) 
    y=np.asarray(y) 
    dataX.append(y) 
    return np.array(dataX)

data_new=create_dataset(train1,train2)

It is returning a dataset of shape 0(2,201,4). I think this is appending differently, but I want row wise appending. so that the new _dataset is of shape= (402,4) with two sets and (603,4) with three sets. I want to generalize as well like if I want for 10 training sets or twenty training sets. How can I do that?

I want to create a dataset from three numpy matrices. - train1 = (204,),train2= train2 = (204,) train3=and train3 = (204,). Basically all sets are of same length. I am applying a sliding window function on each of window 4. Each set become of shape =(201,4) I want a new array in which all these values are appended row wise. Like for first train1 then train2 then train3. andAnd final output set is of size =(603,4).

ThiThis is a slinding window function which converts array of shape (204,) to (201,4)

 

def moving_window(x, length, step=1):
>streams = it.tee(x, length)
return zip(*[it.islice(stream, i, None, step) for stream, i in zip(streams, it.count(step=step))])

def moving_window(x, length, step=1):
    streams = it.tee(x, length) 
    return zip(*[it.islice(stream, i, None, step) for stream, i in zip(streams, it.count(step=step))]) 

Create dataset fucntion is:

def create_dataset(dataset1,dataset2): dataX=[]

x=list(moving_window(dataset1,4))
x=np.asarray(x)
dataX.append(x)
y=list(moving_window(dataset2,4))
y=np.asarray(y)
dataX.append(y)
return np.array(dataX)

data_new=create_dataset(train1,train2)

def create_dataset(dataset1,dataset2):
    dataX=[]       
    x=list(moving_window(dataset1,4))
    x=np.asarray(x) 
    dataX.append(x)
    y=list(moving_window(dataset2,4)) 
    y=np.asarray(y) 
    dataX.append(y) 
    return np.array(dataX)

data_new=create_dataset(train1,train2)

It is returning a dataset of shape 0(2,201,4). I think this is appending differently, but i want row wise appending. so that the new _dataset is of shape= (402,4) with two sets and (603,4) with three sets. I want to generalize as well like if i want for 10 training sets or twenty training sets.how can i do that. Please give valuable suggestions.

I want to create a dataset from three numpy matrices. train1 = (204,),train2= (204,) train3= (204,). Basically all sets are of same length. I am applying a sliding window function on each of window 4. Each set become of shape =(201,4) I want a new array in which all these values are appended row wise. Like for first train1 then train2 then train3. and final output set is of size =(603,4).

Thi is a slinding window function which converts array of shape (204,) to (201,4)

 

def moving_window(x, length, step=1):
>streams = it.tee(x, length)
return zip(*[it.islice(stream, i, None, step) for stream, i in zip(streams, it.count(step=step))])

Create dataset fucntion is:

def create_dataset(dataset1,dataset2): dataX=[]

x=list(moving_window(dataset1,4))
x=np.asarray(x)
dataX.append(x)
y=list(moving_window(dataset2,4))
y=np.asarray(y)
dataX.append(y)
return np.array(dataX)

data_new=create_dataset(train1,train2)

It is returning a dataset of shape 0(2,201,4). I think this is appending differently, but i want row wise appending. so that the new _dataset is of shape= (402,4) with two sets and (603,4) with three sets. I want to generalize as well like if i want for 10 training sets or twenty training sets.how can i do that. Please give valuable suggestions.

I want to create a dataset from three numpy matrices - train1 = (204,), train2 = (204,) and train3 = (204,). Basically all sets are of same length. I am applying a sliding window function on each of window 4. Each set become of shape =(201,4) I want a new array in which all these values are appended row wise. Like for first train1 then train2 then train3. And final output set is of size =(603,4).

This is a slinding window function which converts array of shape (204,) to (201,4)

def moving_window(x, length, step=1):
    streams = it.tee(x, length) 
    return zip(*[it.islice(stream, i, None, step) for stream, i in zip(streams, it.count(step=step))]) 

Create dataset fucntion is:

def create_dataset(dataset1,dataset2):
    dataX=[]       
    x=list(moving_window(dataset1,4))
    x=np.asarray(x) 
    dataX.append(x)
    y=list(moving_window(dataset2,4)) 
    y=np.asarray(y) 
    dataX.append(y) 
    return np.array(dataX)

data_new=create_dataset(train1,train2)

It is returning a dataset of shape 0(2,201,4). I think this is appending differently, but i want row wise appending. so that the new _dataset is of shape= (402,4) with two sets and (603,4) with three sets. I want to generalize as well like if i want for 10 training sets or twenty training sets.how can i do that. Please give valuable suggestions.

Source Link
Hazel
  • 135
  • 2
  • 4
  • 15

Appending to numpy array for creating dataset

I want to create a dataset from three numpy matrices. train1 = (204,),train2= (204,) train3= (204,). Basically all sets are of same length. I am applying a sliding window function on each of window 4. Each set become of shape =(201,4) I want a new array in which all these values are appended row wise. Like for first train1 then train2 then train3. and final output set is of size =(603,4).

Thi is a slinding window function which converts array of shape (204,) to (201,4)

def moving_window(x, length, step=1):
>streams = it.tee(x, length)
return zip(*[it.islice(stream, i, None, step) for stream, i in zip(streams, it.count(step=step))])

Create dataset fucntion is:

def create_dataset(dataset1,dataset2): dataX=[]

x=list(moving_window(dataset1,4))
x=np.asarray(x)
dataX.append(x)
y=list(moving_window(dataset2,4))
y=np.asarray(y)
dataX.append(y)
return np.array(dataX)

data_new=create_dataset(train1,train2)

It is returning a dataset of shape 0(2,201,4). I think this is appending differently, but i want row wise appending. so that the new _dataset is of shape= (402,4) with two sets and (603,4) with three sets. I want to generalize as well like if i want for 10 training sets or twenty training sets.how can i do that. Please give valuable suggestions.