Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

Concatenate two memmapped numpy arrays of different sizes together (Python)?

I'm currently trying to use pysat to solve some k-colorability problems I have. The problem I'm having is a have a CNF formula (a list of lists) of the form:

[1 2 3 4 5 6 7]
[8 9 10 11 12 13 14]
...
[71 72 73 74 75 76 77]
[-60 -80]
[-61 -81]
...

So I have two groupings of array lengths, each can be tens of thousands of lines long, to where it can no longer fit in RAM.

What I tried to do is create two numpy lists using memmap

list1 = np.memmap('temp', dtype = 'float', mode = 'w+', shape = (a, b))
# Fill up list1 with values
list1 = np.memmap('temp', dtype = 'float', mode = 'w+', shape = (c, d))
# Fill up list2 with values

Then run the solver:

with Solver(name=solver_name, bootstrap_with=np.concatenate((list1, list2)), use_timer=True) as s:
   # Setting up timers and other code

Of course, this approach doesn't work and gives me the error message:

ValueError: all the input array dimensions except for the concatenation axis must match exactly

Is there any way I can create a jagged array of arrays stored to disk? Or concatenate two different lists of lists of different shapes that have been stored to disk together to pass into this solver?

Sorry if this is a duplicate. I looked at some of the other questions and couldn't find one that matched my situation.

question from:https://stackoverflow.com/questions/65601785/concatenate-two-memmapped-numpy-arrays-of-different-sizes-together-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...