Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 how to select particular rows data from a array
I am new programmer to python. 
I have a text file having 360 rows and 190 columns of data. 
In matlab, if I load the text file and x_data will be variable of size 360x190 columns.
If I want to select 1 to 20 , 46 to 65, ... rows of data , I simply give 
x_data_train = xdata([1:20,46:65,91:110,136:155,181:200,226:245,271:290,316:335], :);
the resulting x_data_train will be the array of my desired. 

How can do that in python ? 

x_data = np.loadtxt('dataset_300mm.txt', unpack=True)
x_data_train = []
if I do using append operation , the resultant of the array is strange , it is array of 8 subsets of array for 20*192, but I want it to be one array 160*192
I think you should show more on original file structure.
It seems to me there should be an easier way to do this
however this should do it for what you have
x_data_train.append([0:19], [45:64])
assuming you want the first 20 elements which are numbered 0 - 19
and 20 more beginning with the 45th.
I am rather surprised that x_data_train.append(...) works at all. As x_data_train is a casual python list, append() takes only one argument - so you can make it work with either appending one array repeatedly or appending (or extending by) a list of your arrays. In either case you would end with a list (or even a list of lists) of arrays.

Numpy provides .concatenate(), that should work for you:

x_data_test = np.concatenate([x_data[0:20], x_data[45:64]])
Another way would be to construct  some "index" sequence and select on it - it could be list of  numbers of wanted rows or list of booleans.
thank you zivoni np.concatenate works

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  select data based on indice Staph 4 154 Jul-15-2019, 02:05 AM
Last Post: scidam
  display graph in columns and rows william888 1 217 Jul-02-2019, 10:19 AM
Last Post: dataman
  Creating new rows and adding them to empty data frame kapilan15 0 191 May-31-2019, 10:19 AM
Last Post: kapilan15
  comparing each rows of two matrix PhysChem 10 997 May-17-2019, 06:50 AM
Last Post: Gribouillis
  How convert multidimensional array to two dimensional array tkkhan44 1 339 Feb-20-2019, 05:00 AM
Last Post: scidam
  Drop rows from data with zero value Devilish 3 536 Dec-27-2018, 02:06 AM
Last Post: Devilish
  Select specific index for plot rundesquadrat 1 433 Dec-26-2018, 07:47 AM
Last Post: scidam
  Subtract rows (like r[1]-r[2] and r[3]-r[3]) and no pandas pradeepkumarbe 1 369 Dec-18-2018, 01:16 PM
Last Post: ichabod801
  Dataframe Rows Sorting stranger14u 1 455 Dec-17-2018, 11:47 PM
Last Post: scidam
  Write specific rows from pandas dataframe to csv file pradeepkumarbe 3 714 Oct-18-2018, 09:33 PM
Last Post: volcano63

Forum Jump:

Users browsing this thread: 1 Guest(s)