Here are the examples of the python api numpy.fromfile taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
145 Examples
3
View Complete Implementation : test_vq.py
Copyright MIT License
Author : ktraunmueller
Copyright MIT License
Author : ktraunmueller
def test_kmeans2_init(self):
"""Testing that kmeans2 init methods work."""
data = np.fromfile(DATAFILE1, sep=", ")
data = data.reshape((200, 2))
kmeans2(data, 3, minit='points')
kmeans2(data[:, :1], 3, minit='points') # special case (1-D)
# minit='random' can give warnings, filter those
warn_ctx = WarningManager()
warn_ctx.__enter__()
try:
warnings.filterwarnings('ignore',
message="One of the clusters is empty. Re-run")
kmeans2(data, 3, minit='random')
kmeans2(data[:, :1], 3, minit='random') # special case (1-D)
finally:
warn_ctx.__exit__()
3
View Complete Implementation : test_vq.py
Copyright MIT License
Author : ktraunmueller
Copyright MIT License
Author : ktraunmueller
def test_kmeans2_rank1(self):
"""Testing simple call to kmeans2 with rank 1 data."""
data = np.fromfile(DATAFILE1, sep=", ")
data = data.reshape((200, 2))
data1 = data[:, 0]
data2 = data[:, 1]
initc = data1[:3]
code = initc.copy()
code1 = kmeans2(data1, code, iter=1)[0]
code2 = kmeans2(data1, code, iter=2)[0]
3
View Complete Implementation : test_vq.py
Copyright MIT License
Author : ktraunmueller
Copyright MIT License
Author : ktraunmueller
def test_kmeans2_init(self):
"""Testing that kmeans2 init methods work."""
data = np.fromfile(DATAFILE1, sep=", ")
data = data.reshape((200, 2))
kmeans2(data, 3, minit='points')
kmeans2(data[:, :1], 3, minit='points') # special case (1-D)
# minit='random' can give warnings, filter those
warn_ctx = WarningManager()
warn_ctx.__enter__()
try:
warnings.filterwarnings('ignore',
message="One of the clusters is empty. Re-run")
kmeans2(data, 3, minit='random')
kmeans2(data[:, :1], 3, minit='random') # special case (1-D)
finally:
warn_ctx.__exit__()
3
View Complete Implementation : test_vq.py
Copyright MIT License
Author : ktraunmueller
Copyright MIT License
Author : ktraunmueller
def test_kmeans2_rank1(self):
"""Testing simple call to kmeans2 with rank 1 data."""
data = np.fromfile(DATAFILE1, sep=", ")
data = data.reshape((200, 2))
data1 = data[:, 0]
data2 = data[:, 1]
initc = data1[:3]
code = initc.copy()
code1 = kmeans2(data1, code, iter=1)[0]
code2 = kmeans2(data1, code, iter=2)[0]
3
View Complete Implementation : test_vq.py
Copyright MIT License
Author : ktraunmueller
Copyright MIT License
Author : ktraunmueller
def test_kmeans_lost_cluster(self):
"""This will cause kmean to have a cluster with no points."""
data = np.fromfile(DATAFILE1, sep=", ")
data = data.reshape((200, 2))
initk = np.array([[-1.8127404, -0.67128041],
[2.04621601, 0.07401111],
[-2.31149087,-0.05160469]])
res = kmeans(data, initk)
warn_ctx = WarningManager()
warn_ctx.__enter__()
try:
warnings.simplefilter('ignore', UserWarning)
res = kmeans2(data, initk, missing='warn')
finally:
warn_ctx.__exit__()
astert_raises(ClusterError, kmeans2, data, initk, missing='raise')
3
View Complete Implementation : test_vq.py
Copyright MIT License
Author : ktraunmueller
Copyright MIT License
Author : ktraunmueller
def test_kmeans_lost_cluster(self):
"""This will cause kmean to have a cluster with no points."""
data = np.fromfile(DATAFILE1, sep=", ")
data = data.reshape((200, 2))
initk = np.array([[-1.8127404, -0.67128041],
[2.04621601, 0.07401111],
[-2.31149087,-0.05160469]])
res = kmeans(data, initk)
warn_ctx = WarningManager()
warn_ctx.__enter__()
try:
warnings.simplefilter('ignore', UserWarning)
res = kmeans2(data, initk, missing='warn')
finally:
warn_ctx.__exit__()
astert_raises(ClusterError, kmeans2, data, initk, missing='raise')
3
View Complete Implementation : seviri_l1b_hrit.py
Copyright GNU General Public License v3.0
Author : pytroll
Copyright GNU General Public License v3.0
Author : pytroll
def read_prologue(self):
"""Read the prologue metadata."""
with open(self.filename, "rb") as fp_:
fp_.seek(self.mda['total_header_length'])
data = np.fromfile(fp_, dtype=hrit_prologue, count=1)
self.prologue.update(recarray2dict(data))
try:
impf = np.fromfile(fp_, dtype=impf_configuration, count=1)[0]
except IndexError:
logger.info('No IMPF configuration field found in prologue.')
else:
self.prologue.update(recarray2dict(impf))
3
View Complete Implementation : seviri_l1b_native.py
Copyright GNU General Public License v3.0
Author : pytroll
Copyright GNU General Public License v3.0
Author : pytroll
def _read_trailer(self):
hdr_size = native_header.itemsize
data_size = (self._get_data_dtype().itemsize *
self.mda['number_of_lines'])
with open(self.filename) as fp:
fp.seek(hdr_size + data_size)
data = np.fromfile(fp, dtype=native_trailer, count=1)
self.trailer.update(recarray2dict(data))
3
View Complete Implementation : test_vq.py
Copyright MIT License
Author : ktraunmueller
Copyright MIT License
Author : ktraunmueller
def test_kmeans2_rank1_2(self):
"""Testing simple call to kmeans2 with rank 1 data."""
data = np.fromfile(DATAFILE1, sep=", ")
data = data.reshape((200, 2))
data1 = data[:, 0]
code1 = kmeans2(data1, 2, iter=1)
3
View Complete Implementation : test_vq.py
Copyright MIT License
Author : ktraunmueller
Copyright MIT License
Author : ktraunmueller
def test_kmeans2_rank1_2(self):
"""Testing simple call to kmeans2 with rank 1 data."""
data = np.fromfile(DATAFILE1, sep=", ")
data = data.reshape((200, 2))
data1 = data[:, 0]
code1 = kmeans2(data1, 2, iter=1)