Been struggling with this for awhile tonight.
I have numpy arrays with sub arrays of data that have different lengths.
segements_np =
[ [ 30. 20. 20. 30. 40. 50. 50. 60. 50. 70.
70. 60. 70. 60. 80. 80. 90. 90. 90. 100.
100. 110. 120. 560. 510. 460. 430. 380. 380 370
360. 320. 320. 300. 250. 80. 80. 80. 60. 70.
80. 80. 70. 70. 60. 70. 60. 70. 70. 70.
70. 70. 60. 60. 60. 70. 50. 50. 50. 40.
40. 40. 40. 30. 40. 40. 40. 40. 40.]
[ 30. 40. 50. 50. 60. 50. 70. 70. 60. 70.
560. 510. 460. 430. 380. 360. 320. 320. 300. 250.
40. 40. 40. 30. 40. 40. 40. 40. 40.]]
I don’t know what size each segment is when I load the data file nor how many segments I will have. I have script that breaks the data file into these segments.
I’d like to do various calculations on them, hence the numpy array. For instance, I’d like segments_np.max()
However, since they are different sizes of course those commands won’t work as is.
I’ve tried initializing the array size (zeros) to a size I know that won’t be filled by the data I segment and then tried to add the actual data values into that (initialized array). Thus normalizing the size of each sub array. However, I am unable to initialize this properly and unable to copy the data into the initialized array.
I also tried:
peaks_np = array([ segments_np.max(i) for i in range( len(segments_np) ) ])
Would those work and I am doing something wrong or is there a better approach to doing this?
Thanks!!!
Try storing the segments as a Python list of numpy arrays. You can then go