python - Why is stack_data() returning an empty array? -


i have following functions defined. reason, stack_data() returns empty array , cannot figure out why. have suggestions?

general suggestions on improving coding style, form, readability, etc. helpful. general debugging tips great too.

example of should happening: input:
print(stack_data(np.array([[1,1,1,2,2,2,3,3,3],[4,4,4,5,5,5,6,6,6],[7,7,7,8,8,8,9,9,9]]), 0.33))

output: [4,1,4,2,2,3,4,4,4.5,7,7,7.5,9,9]

def _fullsweep_ranges(spec_data):     start = [x x in range(0,len(spec_data[:,1])) \              if spec_data[x,1] == spec_data[:,1].min()]     stop = [x x in range(0,len(spec_data[:,1])) \              if spec_data[x,1] == spec_data[:,1].max()]     return zip(start,stop)  def _remove_partial_fullsweeps(spec_data):     ranges = _fullsweep_ranges(spec_data)     first_min_index = ranges[0][0]     last_max_index = ranges[-1][1]     return spec_data[first_min_index:last_max_index+1,:]  def _flatten_data(spec_data):     row = 0     flat_data = []     running = false     while (row < np.shape(spec_data)[0] - 1):         if not(running):                     start = row         running = true         if spec_data[row,1] != spec_data[row+1,1]:             stop = row             running = false             time = np.mean(spec_data[start:stop,0], axis=0)             start_freq = spec_data[start,1]             freq_step = np.mean(spec_data[start:stop,2], axis=0)             bin_size = spec_data[0,3] * (stop - start)             avg_subspectra = np.mean(spec_data[start:stop,4:], axis=0)             data_row = [time, start_freq, freq_step, bin_size, avg_subspectra]             flat_data.append(data_row)         row += 1     return np.array(flat_data)  def _split_row(row, num_overlap):     return row[:num_overlap], row[num_overlap:-num_overlap], row[-num_overlap:]  def stack_data(spec_data, percent_overlap):     """    input: spectrum data file , percent subspectra overlapping    output: 2d numpy array each row fullsweep overlapping            regions averaged, first col center time of fullsweep,            second col start frequency of fullsweep (this should            same each row), , third col freq_step    """     spec_data = _remove_partial_fullsweeps(spec_data)     spec_data = _flatten_data(spec_data)     ranges = _fullsweep_ranges(spec_data)     num_overlap = math.ceil(len(spec_data[0,4:]) * percent_overlap)     output = []     start,stop in ranges:         center_time = np.mean(spec_data[start:stop+1,0], axis=0)         start_freq = spec_data[start,1]         freq_step = np.mean(spec_data[start:stop+1,2], axis=0)         output_row = [center_time, start_freq, freq_step]         split_data = [_split_row(row, num_overlap) \                       row in spec_data[start:stop+1]]         i, beg, mid, end in enumerate(split_data):             if == 0:                 output_row.extend(beg)             output_row.extend(mid)             if == len(split_data) - 1:                 output_row.extend(end)             else:                 next_beg = split_data[i+1][0]                 averaged = np.mean([end, next_beg], axis=0)                 output_row.extend(averaged)         output.append(output_row)     return np.array(output) 

the error comes _flatten_data() in return-line:

return np.array(flat_data) 

because flat_data in example posted is:

[[nan, 1, nan, 0, array([ nan,  nan,  nan,  nan,  nan])], [nan, 4, nan, 0, array([ nan,  nan,  nan,  nan,  nan])]] 

which not representation of multidimensional array.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -