本文整理汇总了Python中numpy.memmap函数的典型用法代码示例。如果您正苦于以下问题:Python memmap函数的具体用法?Python memmap怎么用?Python memmap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了memmap函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: convert
def convert(in_name, out_name):
"""convert the file identified by filename in_name to a complex numpy array and store it to a file named out_name"""
wav = wave.open(in_name,'rb')
verifyfileformat(wav)
length = wav.getnframes()
channels = wav.getnchannels()
logging.info('length: {} frames, channels: {}'.format(length, channels))
wav.close()
# now that we know the format is valid, access data directly
npinfile = np.memmap(in_name, dtype=np.int16, mode='r', offset=44)
if npinfile.shape[0]/2 != length:
raise TypeError('frame mismatch in direct access')
# our output file, this will be an npy binary holding complex64 types
npfile = np.memmap(out_name, dtype=np.complex64,
mode='w+',
shape=(length,))
# convert input to complex output
npfile[:] = npinfile[0::2] + 1j * npinfile[1::2]
# cleanup
del npinfile
del npfile
开发者ID:hdznrrd,项目名称:parseiq,代码行数:27,代码来源:iq2npy.py
示例2: read_ply
def read_ply(ply_filename):
vfile = tempfile.mktemp()
ffile = tempfile.mktemp()
reader = ply_reader.PlyReader(ply_filename)
v_id = 0
f_id = 0
# Reading the header
for evt, data in reader.read():
if evt == ply_reader.EVENT_HEADER:
n_vertices, n_faces = data
vertices = np.memmap(vfile, dtype='float64', shape = (n_vertices,3),
mode='w+')
faces = np.memmap(ffile, dtype='int64', shape = (n_faces,3),
mode='w+')
break
# Reading the vertices and faces
for evt, data in reader.read():
if evt == ply_reader.EVENT_VERTEX:
current_vertex = data
vertices[v_id] = current_vertex
v_id += 1
elif evt == ply_reader.EVENT_FACE:
faces[f_id] = data
f_id += 1
return vertices, faces
开发者ID:tfmoraes,项目名称:openracm_py,代码行数:30,代码来源:colour_clusters.py
示例3: test_score_memmap
def test_score_memmap():
# Ensure a scalar score of memmap type is accepted
iris = load_iris()
X, y = iris.data, iris.target
clf = MockClassifier()
tf = tempfile.NamedTemporaryFile(mode='wb', delete=False)
tf.write(b'Hello world!!!!!')
tf.close()
scores = np.memmap(tf.name, dtype=np.float64)
score = np.memmap(tf.name, shape=(), mode='r', dtype=np.float64)
try:
cross_val_score(clf, X, y, scoring=lambda est, X, y: score)
# non-scalar should still fail
assert_raises(ValueError, cross_val_score, clf, X, y,
scoring=lambda est, X, y: scores)
finally:
# Best effort to release the mmap file handles before deleting the
# backing file under Windows
scores, score = None, None
for _ in range(3):
try:
os.unlink(tf.name)
break
except WindowsError:
sleep(1.)
开发者ID:YinongLong,项目名称:scikit-learn,代码行数:25,代码来源:test_validation.py
示例4: sim_calc
def sim_calc(self):
nt = self.corpora[0]
self.scores = {}
for corp in self.corpora:
i_nt = []
i_c2 = []
rows = self.ekk_rows[corp[0]]
for i, word in enumerate(self.ekk_rows['NT']):
if word in rows:
i_nt.append(i)
i_c2.append(self.ekk_rows[corp[0]].index(word))
d_c2 = np.memmap(
'{0}{1}/{4}/{2}/{5}_{2}_lems=False_{4}_min_occ={3}_{6}no_stops=False_NORMED.dat'.format(
self.base, corp[0], corp[1], corp[2], self.english, self.prefix, self.svd),
dtype='float32', shape=(len(rows), len(rows)))[i_c2]
d_c2 = d_c2[:, i_c2]
d_nt = np.memmap(
'{0}{1}/{4}/{2}/{5}_{2}_lems=False_{4}_min_occ={3}_{6}no_stops=False_NORMED.dat'.format(
self.base, nt[0], nt[1], nt[2], self.english, self.prefix,
self.svd), dtype='float32',
shape=(len(self.ekk_rows['NT']), len(self.ekk_rows['NT'])))[
i_nt]
d_nt = d_nt[:, i_nt]
self.scores['{0}_{1}'.format('NT', corp[0])] = np.average(np.diag(
1 - pairwise_distances(d_nt, d_c2, metric='cosine',
n_jobs=12)))
开发者ID:sonofmun,项目名称:DissProject,代码行数:26,代码来源:compare_vectors.py
示例5: save
def save(self, dirname = None):
"""Save the current rdfspace to a directory (by default the directory in which indexes are stored)"""
if dirname is None and self._index_dir is not None:
dirname = self._index_dir
if not os.path.exists(dirname):
os.makedirs(dirname)
# We memmap big matrices, as pickle eats the whole RAM
# We don't save the full adjacency matrix
ut_m = np.memmap(os.path.join(dirname, 'ut.dat'), dtype='float64', mode='w+', shape=self._ut_shape)
ut_m[:] = self._ut[:]
s_m = np.memmap(os.path.join(dirname, 's.dat'), dtype='float64', mode='w+', shape=self._s_shape)
s_m[:] = self._s[:]
vt_m = np.memmap(os.path.join(dirname, 'vt.dat'), dtype='float64', mode='w+', shape=self._vt_shape)
vt_m[:] = self._vt[:]
if self._index_dir is None:
# The index is in memory, we'll pickle it with the rest
(adjacency, ut, s, vt) = (self._adjacency, self._ut, self._s, self._vt)
(self._adjacency, self._ut, self._s, self._vt) = (None, None, None, None)
f = open(os.path.join(dirname, 'space.dat'), 'w')
pickle.dump(self, f)
f.close()
(self._adjacency, self._ut, self._s, self._vt) = (adjacency, ut, s, vt)
else:
# Flushing indexes
self._uri_index.close()
self._index_uri.close()
# The index is stored in dbm, we will exclude it from the pickle
(adjacency, ut, s, vt) = (self._adjacency, self._ut, self._s, self._vt)
(self._adjacency, self._ut, self._s, self._vt, self._uri_index, self._index_uri) = (None, None, None, None, None, None)
f = open(os.path.join(dirname, 'space.dat'), 'w')
pickle.dump(self, f)
f.close()
(self._adjacency, self._ut, self._s, self._vt) = (adjacency, ut, s, vt)
self._uri_index = dbm.open(os.path.join(dirname, 'uri_index'), 'r')
self._index_uri = dbm.open(os.path.join(dirname, 'index_uri'), 'r')
开发者ID:anukat2015,项目名称:rdfspace,代码行数:35,代码来源:space.py
示例6: memmap
def memmap(docompute, dowrite, verbose):
afilename = os.path.join(OUT_DIR, "memmap-a.bin")
bfilename = os.path.join(OUT_DIR, "memmap-b.bin")
rfilename = os.path.join(OUT_DIR, "memmap-output.bin")
if dowrite:
t0 = time()
a = np.memmap(afilename, dtype='float32', mode='w+', shape=shape)
b = np.memmap(bfilename, dtype='float32', mode='w+', shape=shape)
# Fill arrays a and b
#row = np.linspace(0, 1, ncols)
row = np.arange(0, ncols, dtype='float32')
for i in range(nrows):
a[i] = row * (i + 1)
b[i] = row * (i + 1) * 2
del a, b # flush data
print("[numpy.memmap] Time for creating inputs:",
round(time() - t0, 3))
if docompute:
t0 = time()
# Reopen inputs in read-only mode
a = np.memmap(afilename, dtype='float32', mode='r', shape=shape)
b = np.memmap(bfilename, dtype='float32', mode='r', shape=shape)
# Create the array output
r = np.memmap(rfilename, dtype='float32', mode='w+', shape=shape)
# Do the computation row by row
for i in range(nrows):
r[i] = eval(expr, {'a': a[i], 'b': b[i]})
if verbose:
print("First ten values:", r[0, :10])
del a, b
del r # flush output data
print("[numpy.memmap] Time for compute & save:", round(time() - t0, 3))
开发者ID:B-Rich,项目名称:PyTables,代码行数:35,代码来源:expression.py
示例7: parse_graph
def parse_graph(self, graph_path, data_dir='data', load_edges=False, extend_paths=2):
graph = parser.Graph(graph_path)
self.from_nodes, self.to_nodes = graph.get_mappings()
graph.save_mappings(self.output_dir)
if load_edges:
self.inverse_degrees = np.memmap(
os.path.join(data_dir, 'inverse_degrees.mat'),
mode='r',
dtype='float32'
)
self.from_to_idxs = np.memmap(
os.path.join(data_dir, 'from_to.mat'),
mode='r',
dtype='int32'
)
self.from_to_idxs = np.reshape(self.from_to_idxs, newshape=(self.inverse_degrees.shape[0], 2))
else:
from_to_idxs, inverse_degrees = graph.extend_graph(max_degree=extend_paths)
self.from_to_idxs = np.memmap(
os.path.join(data_dir, 'from_to.mat'),
mode='r+',
shape=from_to_idxs.shape,
dtype='int32'
)
self.from_to_idxs[:] = from_to_idxs[:]
self.inverse_degrees = np.memmap(
os.path.join(data_dir, 'inverse_degrees.mat'),
mode='r+',
shape=inverse_degrees.shape,
dtype='float32'
)
self.inverse_degrees[:] = inverse_degrees[:]
开发者ID:NobodyInAmerica,项目名称:graph2vec,代码行数:33,代码来源:trainer.py
示例8: _train
def _train(self, x):
# print self.dtype
if len(x) > self.defaultOutputLength:
self.defaultOutputLength = len(x)
self.cacheLength += len(x)
if self.cache is None:
if self.cacheSize == -1:
#self.cache = np.memmap(self.cacheName, dtype='float32', mode='w+', shape = x.shape)
self.cache = np.memmap(self.cacheName, dtype=self.dtype, mode='w+', shape = x.shape)
else:
#self.cache = np.memmap(self.cacheName, dtype='float32', mode='w+', shape = (self.cacheSize, len(x[0])))
self.cache = np.memmap(self.cacheName, dtype=self.dtype, mode='w+', shape = (self.cacheSize, len(x[0])))
elif self.cacheSize == -1:
self.reshape((self.cache.shape[0]+len(x), len(x[0])))
# print x[0][0].dtype.itemsize
# print self.cache._mmap.size()
# #self.cache._mmap.resize( (self.cache.shape[0]+len(x), len(x[0])) )
# print self.cache.shape
# newShape = (self.cache.shape[0]+len(x), len(x[0]))
# memmap_resize( newShape, self.cache )
# del self.cache
# self.cache = np.memmap(self.cacheName, dtype=self.dtype, mode='w+', shape = newShape)
# print "new size: "+str(self.cache._mmap.size())
# print self.cache.reshape(newShape)
self.cache[self.cachePos:self.cachePos+len(x)] = x
# print self.cache._mmap.size()
# print self.cache[0][0]
# print self.cache[0][0].dtype.itemsize
# print "---"
self.cachePos += len(x)
开发者ID:Stewori,项目名称:GNUPFA,代码行数:30,代码来源:cache_node.py
示例9: main
def main(A):
"""convolve the tau(mass) field,
add in thermal broadening and redshift distortion """
sightlines = Sightlines(A)
maker = SpectraMaker(A, sightlines)
fgpa = FGPAmodel(A)
Npixels = sightlines.Npixels.sum()
spectaureal = numpy.memmap(A.SpectraOutputTauReal, mode='w+',
dtype='f4', shape=Npixels)
spectaured = numpy.memmap(A.SpectraOutputTauRed, mode='w+',
dtype='f4', shape=Npixels)
specdelta = numpy.memmap(A.SpectraOutputDelta, mode='w+',
dtype='f4', shape=Npixels)
def work(i):
sl2 = slice(sightlines.PixelOffset[i],
sightlines.PixelOffset[i] + sightlines.Npixels[i])
result = maker.convolve(i, Afunc=fgpa.Afunc, Bfunc=fgpa.Bfunc)
spectaureal[sl2] = result.taureal
spectaured[sl2] = result.taured
specdelta[sl2] = result.delta
sightlines.Z_RED[i] = result.Zqso
chunkmap(work, range(len(sightlines)), 100)
spectaureal.flush()
spectaured.flush()
specdelta.flush()
sightlines.Z_RED.flush()
开发者ID:rainwoodman,项目名称:lyamock,代码行数:31,代码来源:spectra.py
示例10: extract_to_memmap
def extract_to_memmap(self):
"""
Allocate a memmap, fill it with extracted features, return r/o view.
"""
filename = self.filename
feature_shp = self.feature_shp
print('Creating memmap %s for features of shape %s' % (
filename,
str(feature_shp)))
features_fp = np.memmap(filename,
dtype='float32',
mode='w+',
shape=feature_shp)
info = open(filename+'.info', 'w')
cPickle.dump(('float32', feature_shp), info)
del info
self.extract_to_storage(features_fp)
# -- docs here:
# http://docs.scipy.org/doc/numpy/reference/generated/numpy.memmap.html
# say that deletion is the way to flush changes !?
del features_fp
rval = np.memmap(self.filename,
dtype='float32',
mode='r',
shape=feature_shp)
return rval
开发者ID:yamins81,项目名称:simffa,代码行数:28,代码来源:theano_slm.py
示例11: next
def next(self):
# for python 2.x
# Keep under lock only the mechainsem which advance the indexing of each batch
# see # http://anandology.com/blog/using-iterators-and-generators/
with self.lock:
song_idx, self.cur_song = self.cur_song, self.cur_song+1
bX, bY = (None, None)
if song_idx < self.n_songs:
x_path = self.data[self.sidstr[song_idx]]['X_path']
y_path = self.data[self.sidstr[song_idx]]['y_path']
bX = np.memmap(
x_path,
dtype='float32',
mode='r',
shape=tuple(self.data[self.sidstr[song_idx]]['X_shape'])
)
bY = np.memmap(
y_path,
dtype='float32',
mode='r',
shape=tuple(self.data[self.sidstr[song_idx]]['y_shape'])
)
return bX, bY
else:
raise StopIteration()
return bX, bY
开发者ID:smajida,项目名称:cnn-music-structure,代码行数:27,代码来源:keras_net.py
示例12: __init__
def __init__(self,fdata,fndata):
#dump to binary
print('Initialize binary from ' + fdata)
if (not os.path.isfile(fndata)):
print('create Epix100a flat file ' + fndata + ' from ' + fdata)
datain=Epix100a(fdata);
#write header
binheader=np.zeros(16).astype(np.uint32);
binheader[0:6]=[datain.nframes, datain.my*datain.mx, datain.my, datain.mx, datain.nblocks, datain.nbcols];
binheader.tofile(fndata);
#write data
dataout=np.memmap(fndata,dtype=np.int16,mode='r+', shape=(datain.nframes,datain.my,datain.mx),offset=64);
t0=time.clock();
for iframe in range(datain.nframes):
dataout[iframe]=datain.frame(iframe);
if (iframe%100==0):
#progress(iframe,nframes,iframe);
print (str(iframe)+' - '+str(1000*(time.clock()-t0)/(iframe+1))+' ms. average frame: '+str(np.mean(datain.frame(iframe))))
dataout.flush();
del dataout;
del datain;
#get nr of frames
else:
print(fndata + ' file already exists.')
data=np.memmap(fndata,dtype=np.uint32,mode='r',shape=((64)),offset=0);
self.nframes=data[0]; self.nframesize=data[1]; self.my=data[2]; self.mx=data[3]; self.nblocks=data[4]; self.nbcols=data[5];
self.data=np.memmap(fndata,dtype=np.int16,mode='c',shape=(self.nframes,self.my,self.mx),offset=64);
开发者ID:perhansson,项目名称:daq,代码行数:34,代码来源:epix.py
示例13: get_sequence
def get_sequence(mraw_path, file_shape, nmax=None, offset=0):
'''
Get a sequence of image files as 3D numpy array.
:param mraw_path: path to .mraw file containing image data
:param file_shape: tuple, (ntotal, height, width) of images in .mraw file
:param nmax: maximum number of images in sequence
:param offset: First image to be read
:return: 3D array of image sequence
'''
ntotal, h, w = file_shape
byte_size = 2*h*w # Number of bytes for one image
byte_offset = offset * byte_size # Offset to first byte to be read
# If only a single image was requested:
if nmax and nmax == 1:
with open(mraw_path, 'rb') as mraw:
imarray = np.memmap(mraw, dtype=np.uint16, offset=byte_offset, mode='r', shape=(h, w))
# Only display nmax or less images:
elif nmax and ntotal > nmax:
image_step = ntotal//nmax
with open(mraw_path, 'rb') as mraw:
memmap = np.memmap(mraw, dtype=np.uint16, offset=byte_offset, mode='r', shape=(ntotal-offset, h, w))
imarray = memmap[::image_step, :, :]
# If there are less than nmax images:
else:
with open(mraw_path, 'rb') as mraw:
imarray = np.memmap(mraw, dtype=np.uint16, offset=byte_offset, mode='r', shape=(ntotal-offset, h, w))
return imarray
开发者ID:ladisk,项目名称:pyDIC,代码行数:30,代码来源:dic_tools.py
示例14: __next__
def __next__(self):
#check to see if at end of chunks
if self._chunk_counter==self.num_chunks:
offset = int(self._chunk_counter * self.chunksize)
row_size = self.rmndr_row_size
self._chunk_counter += 1
elif self._chunk_counter < self.num_chunks:
offset = int(self._chunk_counter * self.chunksize)
end_dp = (self._chunk_counter+1) + self.chunksize
row_size = self.chunk_row_size
self._chunk_counter += 1
elif self._chunk_counter > self.num_chunks:
raise StopIteration
if self.abr.header['f_structure']['nDataFormat'][0]==1: #float data
data = memmap(self.abr.fid, dtype = float32, shape = (row_size,self.ncols), offset = offset+self.offset_base)
return data
elif self.abr.header['f_structure']['nDataFormat'][0]==0: #integer data
try:
data = memmap(self.abr.fid, dtype = int16, shape = (row_size,self.ncols),
mode = 'r',offset = offset + self.offset_base)
except ValueError:
pdb.set_trace()
data = data[:].astype(float32)
data = self.abr.scale_int_data(data)
return data
开发者ID:matthewperkins,项目名称:abf_reader,代码行数:27,代码来源:chunker.py
示例15: update
def update(self):
""" Updates L-BFGS algorithm history
"""
unix.cd(self.path)
s = self.load('m_new') - self.load('m_old')
y = self.load('g_new') - self.load('g_old')
m = len(s)
n = self.memory
if self.memory_used == 0:
S = np.memmap('LBFGS/S', mode='w+', dtype='float32', shape=(m, n))
Y = np.memmap('LBFGS/Y', mode='w+', dtype='float32', shape=(m, n))
S[:, 0] = s
Y[:, 0] = y
self.memory_used = 1
else:
S = np.memmap('LBFGS/S', mode='r+', dtype='float32', shape=(m, n))
Y = np.memmap('LBFGS/Y', mode='r+', dtype='float32', shape=(m, n))
S[:, 1:] = S[:, :-1]
Y[:, 1:] = Y[:, :-1]
S[:, 0] = s
Y[:, 0] = y
if self.memory_used < self.memory:
self.memory_used += 1
return S, Y
开发者ID:PrincetonUniversity,项目名称:seisflows,代码行数:30,代码来源:LBFGS.py
示例16: compute_pca
def compute_pca(data_path=os.path.join(BASE_DIR, 'data/memmap/'),
out_path=os.path.join(BASE_DIR, 'data/'),
batch_size=500, image_size=3*300*300):
ipca = IncrementalPCA(n_components=3, batch_size=batch_size)
path = os.path.join(data_path, 'tn_x.dat')
train = np.memmap(path, dtype=theano.config.floatX, mode='r+', shape=(4044,image_size))
n_samples, _ = train.shape
for batch_num, batch in enumerate(gen_batches(n_samples, batch_size)):
X = train[batch,:]
X = np.reshape(X, (X.shape[0], 3, int(image_size/3)))
X = X.transpose(0, 2, 1)
X = np.reshape(X, (reduce(np.multiply, X.shape[:2]), 3))
ipca.partial_fit(X)
path = os.path.join(data_path, 'v_x.dat')
valid = np.memmap(path, dtype=theano.config.floatX, mode='r+', shape=(500,image_size))
n_samples, _ = valid.shape
for batch_num, batch in enumerate(gen_batches(n_samples, batch_size)):
X = valid[batch,:]
X = np.reshape(X, (X.shape[0], 3, int(image_size/3)))
X = X.transpose(0, 2, 1)
X = np.reshape(X, (reduce(np.multiply, X.shape[:2]), 3))
ipca.partial_fit(X)
eigenvalues, eigenvectors = np.linalg.eig(ipca.get_covariance())
eigenvalues.astype('float32').dump(os.path.join(out_path, 'eigenvalues.dat'))
eigenvectors.astype('float32').dump(os.path.join(out_path, 'eigenvectors.dat'))
开发者ID:121onto,项目名称:noaa,代码行数:32,代码来源:preproc.py
示例17: get_session
def get_session(self, session=-1, signal="data"):
"""Return the aggregate data array of a session
If the session consists in many buffers, they are concatenated into a
single buffer loaded in memory.
If the data is a single file, it is memmaped as an array.
"""
sessions = self.list_sessions()
if isinstance(session, int):
session_id = sessions[session]
elif session in sessions:
session_id = session
else:
raise ValueError("No such session %r" % session)
signal_folder = os.path.join(self.data_folder, session_id, signal)
data_files = os.listdir(signal_folder)
dtypes = [self.decode_dtype(filename) for filename in data_files]
if len(data_files) == 0:
return np.array([])
elif len(data_files) == 1:
return np.memmap(os.path.join(signal_folder, data_files[0]), dtype=dtypes[0])
else:
return np.concatenate(
[np.memmap(os.path.join(signal_folder, f), dtype=dtype) for f, dtype in zip(data_files, dtypes)]
)
开发者ID:Jared314,项目名称:pythinkgear,代码行数:27,代码来源:collect.py
示例18: convert
def convert(cls, file_path):
meta_path = file_path + '.meta'
index_path = file_path + '.idx'
edge_path = file_path + '.bin'
with open(file_path, 'r') as f:
nodes, edges = map(int, f.readline().split())
nodes, edges = nodes + 1, edges + 1
with open(meta_path, 'w+') as m:
m.write('{} {}'.format(nodes, edges))
index_map = np.memmap(index_path, dtype='uint32', mode='w+', shape=(nodes, 2))
edge_map = np.memmap(edge_path, dtype='uint32', mode='w+', shape=(edges, 1))
current = 0
count = 0
degree = 0
for line in f:
origin, destination = map(int, line.split())
while current < origin:
index_map[current] = (count - degree, degree)
degree = 0
current += 1
if current == origin:
degree += 1
edge_map[count] = destination
count += 1
index_map[current] = (count - degree, degree)
index_map.flush()
edge_map.flush()
开发者ID:mmap-graph,项目名称:mmap-python,代码行数:31,代码来源:models.py
示例19: main
def main(A):
sightlines = Sightlines(A)
fgpa = FGPAmodel(A)
Npixels = sightlines.Npixels.sum()
specloglam = numpy.memmap(A.SpectraOutputLogLam, mode='w+',
dtype='f4', shape=Npixels)
# now save LogLam of the pixels for ease of access
# (not used by our code)
LogLamGrid = A.LogLamGrid
LogLamCenter = 0.5 * (LogLamGrid[1:] + LogLamGrid[:-1])
for index in range(len(sightlines)):
sl2 = slice(sightlines.PixelOffset[index],
sightlines.PixelOffset[index] + sightlines.Npixels[index])
sl = slice(
sightlines.LogLamGridIndMin[index],
sightlines.LogLamGridIndMax[index] - 1)
specloglam[sl2] = LogLamCenter[sl]
specloglam.flush()
# now save QSONpixel for ease of access
# (not used by our code)
QSONpixel = numpy.memmap(A.QSONpixel, mode='w+',
dtype='i4', shape=len(sightlines))
QSONpixel[...] = numpy.int32(sightlines.Npixels)
QSONpixel.flush()
开发者ID:rainwoodman,项目名称:lyamock,代码行数:26,代码来源:export.py
示例20: LogOfMatrix
def LogOfMatrix(ccMapObj):
ccMapObj.make_readable()
LogHiCmap = CCMAP()
LogHiCmap.path2matrix = os.getcwd() + '/nparray_' + getRandomName() + '.bin'
LogHiCmap.shape = ccMapObj.shape
LogHiCmap.xticks = ccMapObj.xticks
LogHiCmap.yticks = ccMapObj.yticks
LogHiCmap.binsize = ccMapObj.binsize
LogHiCmap.bLog = True
bNonZeros = None
#if ccMapObj.bNoData is not None:
# LogHiCmap.bNoData = ccMapObj.bNoData
# bNonZeros = ~LogHiCmap.bNoData
#else:
LogHiCmap.bNoData = np.all( ccMapObj.matrix == 0.0, axis=0)
bNonZeros = ~LogHiCmap.bNoData
# Log of part of matrix containing data
path2matrixA = os.getcwd() + '/nparray_' + getRandomName() + '.bin'
A = (ccMapObj.matrix[bNonZeros,:])[:,bNonZeros] # Selected row-column which are not all zeros
BinMatrixA = np.memmap(path2matrixA, dtype=dtype_npBINarray, mode='w+', shape=A.shape)
BinMatrixA[:] = np.log10(A)[:]
BinMatrixA.flush()
# Assigning minvalue and maxvalue
LogHiCmap.maxvalue = float(np.amax(BinMatrixA))
minvalue = np.amin(BinMatrixA)
v_steps = np.linspace(minvalue, LogHiCmap.maxvalue, 100)
LogHiCmap.minvalue = minvalue - (v_steps[1] - v_steps[0])
# Making full matrix
BinLogMatrix = np.memmap(LogHiCmap.path2matrix, dtype=dtype_npBINarray, mode='w+', shape=LogHiCmap.shape)
A_i = -1
A_j = 0
for i in range(BinLogMatrix.shape[0]):
if not LogHiCmap.bNoData[i]:
A_i += 1
A_j = 0
for j in range(BinLogMatrix.shape[1]):
if LogHiCmap.bNoData[i] or LogHiCmap.bNoData[j]:
BinLogMatrix[i][j] = LogHiCmap.minvalue
else:
BinLogMatrix[i][j] = BinMatrixA[A_i][A_j]
A_j += 1
BinLogMatrix.flush()
del BinLogMatrix
del BinMatrixA
try:
os.remove(path2matrixA)
except:
pass
return LogHiCmap
开发者ID:rjdkmr,项目名称:gcMapExplorer,代码行数:60,代码来源:ccmap.py
注:本文中的numpy.memmap函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论