Python/Numpy: Automating to save generated data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RockRoll
    New Member
    • Jul 2020
    • 10

    Python/Numpy: Automating to save generated data

    I want to save a particular number of values in maps I create. For example, when creating (4064x1) values, I want to save first (1000x1) in map1, next (1000x1) in map2 and so on. The last map will have remaining (64x1) elements. I need these maps later for fast processing.

    Now the issue is I want to automate this as the number 4064 varies based on data I analyze. Here is simplsitic version of something I tried and is working (L is 1000 and index is reset to zero as I move from one map to the other).

    Any suggestions on how to make this creative?
    Code:
    L = 1000
    index = 0
    count = 0
    # manually creating maps
    fp1 = np.memmap('map1.dat', dtype='float64', mode='w+', shape=(L,1))
    fp2 = np.memmap('map2.dat', dtype='float64', mode='w+', shape=(L,1))
    fp3 = np.memmap('map3.dat', dtype='float64', mode='w+', shape=(L,1))
    ...
    # manually pushing generated values into created maps
    if count < L:
        fp1[index,0] = delta # delta is some float64 value I am creating in each iteration of a parent loop
     
    if count == L:
        index = 0
     
    if L <= count < 2*L:
        fp2[index,0] = delta
     
    if count == 2*L:
        index = 0
     
    if 2*L <= count < 3*L:
        fp3[index,0]=delta
     
    ...
     
    count += 1
    index += 1
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Questions
    1. Your text seems to suggest splitting an existing block of data in chunks of 1000 but your code seems to suggest generating values 1 at a time and dynamically creating new memory maps when a new value tips over the threshold. Which is it because they will require different solutions? The second scenario requires code that maintains state.
    2. Do you need to be able to access all the memmaps after the process is finished or once finished does nothing further happen so for example there is no need to be able to access the first memmap once you have started creating the second?

    Comment

    Working...