本文整理匯總了Python中scipy.sparse.indptr方法的典型用法代碼示例。如果您正苦於以下問題:Python sparse.indptr方法的具體用法?Python sparse.indptr怎麽用?Python sparse.indptr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scipy.sparse
的用法示例。
在下文中一共展示了sparse.indptr方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load
# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import indptr [as 別名]
def load(cls, fname, mmap=None):
"""
Load a previously saved object from file (also see `save`).
If the object was saved with large arrays stored separately, you can load
these arrays via mmap (shared memory) using `mmap='r'`. Default: don't use
mmap, load large arrays as normal objects.
"""
logger.info("loading %s object from %s" % (cls.__name__, fname))
subname = lambda suffix: fname + '.' + suffix + '.npy'
obj = unpickle(fname)
for attrib in getattr(obj, '__numpys', []):
logger.info("loading %s from %s with mmap=%s" % (attrib, subname(attrib), mmap))
setattr(obj, attrib, numpy.load(subname(attrib), mmap_mode=mmap))
for attrib in getattr(obj, '__scipys', []):
logger.info("loading %s from %s with mmap=%s" % (attrib, subname(attrib), mmap))
sparse = unpickle(subname(attrib))
sparse.data = numpy.load(subname(attrib) + '.data.npy', mmap_mode=mmap)
sparse.indptr = numpy.load(subname(attrib) + '.indptr.npy', mmap_mode=mmap)
sparse.indices = numpy.load(subname(attrib) + '.indices.npy', mmap_mode=mmap)
setattr(obj, attrib, sparse)
for attrib in getattr(obj, '__ignoreds', []):
logger.info("setting ignored attribute %s to None" % (attrib))
setattr(obj, attrib, None)
return obj
示例2: load
# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import indptr [as 別名]
def load(cls, fname, mmap=None):
"""
Load a previously saved object from file (also see `save`).
If the object was saved with large arrays stored separately, you can load
these arrays via mmap (shared memory) using `mmap='r'`. Default: don't use
mmap, load large arrays as normal objects.
"""
#logger.info("loading %s object from %s" % (cls.__name__, fname))
subname = lambda suffix: fname + '.' + suffix + '.npy'
obj = unpickle(fname)
for attrib in getattr(obj, '__numpys', []):
logger.info("loading %s from %s with mmap=%s" % (attrib, subname(attrib), mmap))
setattr(obj, attrib, numpy.load(subname(attrib), mmap_mode=mmap))
for attrib in getattr(obj, '__scipys', []):
logger.info("loading %s from %s with mmap=%s" % (attrib, subname(attrib), mmap))
sparse = unpickle(subname(attrib))
sparse.data = numpy.load(subname(attrib) + '.data.npy', mmap_mode=mmap)
sparse.indptr = numpy.load(subname(attrib) + '.indptr.npy', mmap_mode=mmap)
sparse.indices = numpy.load(subname(attrib) + '.indices.npy', mmap_mode=mmap)
setattr(obj, attrib, sparse)
for attrib in getattr(obj, '__ignoreds', []):
#logger.info("setting ignored attribute %s to None" % (attrib))
setattr(obj, attrib, None)
return obj
示例3: _load_specials
# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import indptr [as 別名]
def _load_specials(self, fname, mmap, compress, subname):
"""
Loads any attributes that were stored specially, and gives the same
opportunity to recursively included SaveLoad instances.
"""
mmap_error = lambda x, y: IOError(
'Cannot mmap compressed object %s in file %s. ' % (x, y) +
'Use `load(fname, mmap=None)` or uncompress files manually.')
for attrib in getattr(self, '__recursive_saveloads', []):
cfname = '.'.join((fname, attrib))
logger.info("loading %s recursively from %s.* with mmap=%s" % (
attrib, cfname, mmap))
getattr(self, attrib)._load_specials(cfname, mmap, compress, subname)
for attrib in getattr(self, '__numpys', []):
logger.info("loading %s from %s with mmap=%s" % (
attrib, subname(fname, attrib), mmap))
if compress:
if mmap:
raise mmap_error(attrib, subname(fname, attrib))
val = numpy.load(subname(fname, attrib))['val']
else:
val = numpy.load(subname(fname, attrib), mmap_mode=mmap)
setattr(self, attrib, val)
for attrib in getattr(self, '__scipys', []):
logger.info("loading %s from %s with mmap=%s" % (
attrib, subname(fname, attrib), mmap))
sparse = unpickle(subname(fname, attrib))
if compress:
if mmap:
raise mmap_error(attrib, subname(fname, attrib))
with numpy.load(subname(fname, attrib, 'sparse')) as f:
sparse.data = f['data']
sparse.indptr = f['indptr']
sparse.indices = f['indices']
else:
sparse.data = numpy.load(subname(fname, attrib, 'data'), mmap_mode=mmap)
sparse.indptr = numpy.load(subname(fname, attrib, 'indptr'), mmap_mode=mmap)
sparse.indices = numpy.load(subname(fname, attrib, 'indices'), mmap_mode=mmap)
setattr(self, attrib, sparse)
for attrib in getattr(self, '__ignoreds', []):
logger.info("setting ignored attribute %s to None" % (attrib))
setattr(self, attrib, None)