Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import numpy as np
  2.  
  3. channels, width, height=200, 1700, 350
  4. # and out goal to get
  5. # channels = 10, width = 1700, height=350
  6. NUMBER_OF_DIM_TO_REDUCE = 10
  7.  
  8. sample_matrix = np.random.randint(0, 100, size=(width, height, channels))
  9.  
  10. # declare only once from scikit learn
  11. pca = None
  12.  
  13. def get_reduced_dimensions(input_matrix):
  14. # do dimension reduction on
  15. # in theory you want to return of shape
  16. # height, NUMBER_OF_DIM_TO_REDUCE
  17. # but i am just returning random one now
  18. return np.random.randint(0, 100, size=(height, NUMBER_OF_DIM_TO_REDUCE))
  19.  
  20. def get_channel_as_pca_input(matrix, column):
  21. return matrix[column,:,:]
  22.  
  23. # we need to reduce from 200 channels to day 10, so we need to get all channels for a given channel
  24. all_channels_for_col_0 = get_channel_as_pca_input(sample_matrix, 0)
  25. # all_channels_for_col_0.shape = 350, 200
  26. # send all_channels_for_col_0 through get_reduced_dimensions function
  27.  
  28. new_matrix_with_reduced_dimensions = np.random.randint(0, 100, size=(width, height, NUMBER_OF_DIM_TO_REDUCE))
  29.  
  30. for i in range(width):
  31. all_channels = get_channel_as_pca_input(sample_matrix, i)
  32. reduced_dimension = get_reduced_dimensions(all_channels)
  33. new_matrix_with_reduced_dimensions[i,:,:] = reduced_dimension
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement