本文整理汇总了Python中numpy.loads函数的典型用法代码示例。如果您正苦于以下问题:Python loads函数的具体用法?Python loads怎么用?Python loads使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loads函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: k_means_distance
def k_means_distance(self, centers, result_name=None):
"""
Computes the distance between each row and each of the given center vectors for k-means
"""
if centers.shape[1] != self.__cols:
raise BaseException('Dimensions of matrix and centers do not match')
if result_name == None:
result_name = MatrixFactory.getRandomMatrixName()
redwrap = RedisWrapper(self.context.redis_master, self.context.key_manager)
prefix = 'dist(' + self.__name + ',' + centers.name() + ')';
dist_job = kmeans_jobs.KMeansDistanceJob(self.context, self, centers, prefix)
parts = dist_job.run()
for p in range(0,len(parts)):
part_name = parts[p]
m = self.context.redis_master.lpop(part_name)
sum = None
while m != None:
if sum == None:
sum = numpy.loads(m)
else:
sum += numpy.loads(m)
m = self.context.redis_master.lpop(part_name)
self.context.redis_master.delete(part_name)
redwrap.create_block(self.context.key_manager.get_block_name(result_name, p, 0), numpy.sqrt(sum))
res = Matrix(self.__rows, centers.shape[0], result_name, self.context)
return res
示例2: run
def run(self):
video_input = self.get_input("videoInput")
video_input_resized = self.get_input("videoInputResized")
gif_data_output = self.get_output("gifData")
script = FrameAnalyzer()
while self.running():
# read frames - full scale and thumb
frame_obj = video_input.read()
frame_obj_resized = video_input_resized.read()
frame = np.loads(frame_obj)
frame_resized = np.loads(frame_obj_resized)
with self.filters_lock:
script.change_settings(\
self.get_parameter("max_gif_length"),
self.get_parameter("min_gif_length"),
self.get_parameter("min_time_between_gifs"),
self.get_parameter("max_acceptable_distance") )
loop_data = script(frame, frame_resized)
if loop_data and len(loop_data)==4:
file_path, w, h, frames_count = loop_data
self.__send_to_next_service(gif_data_output, file_path, w, h, frames_count)
self.__push_notification()
示例3: socketcomm
def socketcomm(port, pipec, flags, uarr, dat_size=156):
"""Callback function to deal with incoming tcp communication.
pipec,pipeu and pipesoc are pipe objects
pipec: describes position of camera
pipeu: describes orientation of camera.
sends (True, data) for good data
sends (False,.......) for bad data or loop not running
pipesoc: fill socket objects and send to __main__
"""
# Flags
sockets = []
waiting_for_data = True
# initialise socket object
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
serversocket.bind((_TCP_SOCKET_HOST, port))
serversocket.listen(1)
serversocket.setblocking(0)
# add server socket to list of sockets
sockets.append(serversocket)
# create epoll object
_epoll = select.epoll()
# register interest in read events on the server socket
_epoll.register(serversocket.fileno(), select.EPOLLIN)
while waiting_for_data:
events = _epoll.poll(1)
for fileno, event in events:
if fileno == serversocket.fileno():
# initialise client socket object
clientsocket, clientaddr = serversocket.accept()
clientsocket.setblocking(0)
# register client socket on epoll
_epoll.register(clientsocket.fileno(), select.EPOLLIN)
sockets.append(clientsocket)
elif event & select.EPOLLIN:
# read event on client socket
content = clientsocket.recv(dat_size)
if content[0] == "u":
# pipeu.send((True,True,np.loads(content[1:])))
with uarr.get_lock():
uarr.get_obj()[:3] = np.loads(content[1:]).ravel()
flags.value = 2
elif content[0] == "d":
# pipeu.send((False,True))
flags.value = 1
elif content[0] == "c":
pipec.send(np.loads(content[1:]))
elif content[0] == "e":
# pipeu.send((False,False))
flags.value = 0
waiting_for_data = False
for i in sockets:
_epoll.unregister(i.fileno())
elif event & select.EPOLLHUP:
for i in sockets:
_epoll.unregister(i.fileno())
i.close()
示例4: get_correlation
def get_correlation(self):
pkt = self._request('') # raises NoCorrelation if none ready
self.logger.debug('received: %r' % pkt)
data = pkt[self._header_size:] # should be 3 arrays and 2 floats
corr_time, left, right, current, total = self._header_struct.unpack(pkt[:self._header_size])
lagss, visibss, fitss, m, c = self.unpacker.unpack(data)
return (
corr_time, left, right, current, total, # header information
loads(lagss), loads(visibss), loads(fitss), m, c # data
)
示例5: load_model
def load_model(self, filename, delimiter = '<DELIMITER>'):
"""
Load model parameters from the file provided
"""
try:
infile = open(filename, 'r')
except IOError:
print "Could not open filename '" + filename + "'."
return
# Get the number of units in each layer
data = infile.read()
data = data.split(delimiter)
self.num_visible = int(data[0])
self.num_hidden = int(data[1])
self.num_rnn = int(data[2])
# Read each line and convert to weight matrices
self.Whv = np.loads(data[3])
self.Wuh = np.loads(data[4])
self.Wuv = np.loads(data[5])
self.Wuu = np.loads(data[6])
self.Wvu = np.loads(data[7])
self.bias_visible = np.loads(data[8])
self.bias_hidden = np.loads(data[9])
self.bias_rnn = np.loads(data[10])
self.initial_rnn = np.loads(data[11])
infile.close()
示例6: socket_cb1
def socket_cb1(socket,val):
global u1,c1, running1,fr1,dat1
if val[0] == 'u':
u1 = np.loads(val[1:])
fr1 += 1
dat1 = True
elif val[0] == 'c':
c1 = np.loads(val[1:])
elif val[0] == 'd':
dat1 = False
elif val[0] == 'e':
dat1 = False
running1 = False
示例7: socket_cb2
def socket_cb2(socket,val):
global u2,c2, running2,fr2,dat2
if val[0] == 'u':
u2 = np.loads(val[1:])
fr2 += 1
dat2 = True
elif val[0] == 'c':
c2 = np.loads(val[1:])
elif val[0] == 'd':
dat2 = False
elif val[0] == 'e':
dat2 = False
running2 = False
示例8: _do_numeric
def _do_numeric(self, value, path):
if PY_VER > 2:
data = value['data']
if isinstance(data, str):
data = value['data'].encode('utf-8')
junk = gunzip_string(base64.decodebytes(data))
result = numpy.loads(junk, encoding='bytes')
else:
junk = gunzip_string(value['data'].decode('base64'))
result = numpy.loads(junk)
self._numeric[value['id']] = (path, result)
self._obj_cache[value['id']] = result
return result
示例9: show_frame
def show_frame(self, input_connector, video_frame_label):
obj = input_connector.read()
frame = np.loads(obj) # załadownaie ramki do obiektu NumPy
img = Image.fromarray(frame)
imgTk = ImageTk.PhotoImage(image=img)
video_frame_label.imgTk = imgTk
video_frame_label.configure(image=imgTk)
示例10: check
def check(self):
word_errors = 0
file_errors = 0
t0 = time.time()
self.get_tree()
files_read = 0
for f in self.tree:
try:
arr = np.loads(f)
files_read += 1
except:
file_errors += 1
word_errors += np.sum(arr==self.chunk)
t1 = time.time()
speed = self.sweeplen / (1e6 * (t1-t0))
msg = "\nread %.2f TB at %.2f MB/s"%(files_read*self.flen,speed)
msg += "\n\t\t failed file reads = %i\n" %(file_errors)
msg += "\n\t\t word errors = %i\n\n" %(word_errors)
logging.info(msg)
示例11: run
def run(self): # główna metoda usługi
video_input = self.get_input("videoInput") # obiekt interfejsu wejściowego
video_output = self.get_output("videoOutput")
input_start = True
out = None
while self.running(): # pętla główna usługi
try:
frame_obj = video_input.read() # odebranie danych z interfejsu wejściowego
video_output.send(frame_obj)
except Exception as e:
video_input.close()
if out != None:
out.release()
break
if input_start:
video_format = self.get_parameter("videoFormat")
print video_format
fourcc = cv2.VideoWriter_fourcc(*"XVID")
out = cv2.VideoWriter(
"output.avi", fourcc, video_format[0], (int(video_format[1]), int(video_format[2]))
)
input_start = False
frame = np.loads(frame_obj) # załadowanie ramki do obiektu NumPy
out.write(frame)
示例12: save_to_mat_file
def save_to_mat_file(init_data, outfile_name):
def get_list(vocab_dict):
l=np.zeros((len(vocab_dict),), dtype=np.object)
for w, i in vocab_dict.iteritems():
l[i]=w
return l
laff = lambda nm : np.loads(init_data[nm])
tag_vocab=get_list(init_data["tag_vocab"])
word_vocab=get_list(init_data["word_vocab"])
with open(outfile_name, "wb") as f:
savemat(f,
dict(word_context_size=init_data["word_context_size"],
embedding_size=init_data["embedding_size"],
objective_type=init_data["objective_type"],
param_reg_type=init_data["param_reg_type"],
param_reg_weight=init_data["param_reg_weight"],
tag_vocab=tag_vocab,
word_vocab=word_vocab,
tagemb=laff("na_tag_emb"),
wordemb=laff("na_word_emb"),
T1=laff("nam_T1"),
T2=laff("nam_T2"),
Tt1=laff("nam_Ttld1"),
Tt2=laff("nam_Ttld2"),
W=laff("nat_W"),
Wt=laff("nat_Wtld"),
S=laff("na_S_emb")),
oned_as='column',
format='5',
appendmat=False)
示例13: k_means_recalc
def k_means_recalc(cmd_ctx):
m = _get_matrix_block(cmd_ctx, cmd_ctx.cmdArgs[0])
d = _get_matrix_block(cmd_ctx, cmd_ctx.cmdArgs[1])
result_prefix = cmd_ctx.cmdArgs[2]
# Only count if prefix is given
counter_prefix = None
if len(cmd_ctx.cmdArgs) > 3:
counter_prefix = cmd_ctx.cmdArgs[3]
result = {}
mincols = numpy.argmin(d, axis=1)
# Find the nearest center for each record and add the record to the centers sum
# Also count how many records are nearest to each center
rowcount = 0
for col in mincols:
if counter_prefix != None:
cmd_ctx.redis_master.incr(counter_prefix + str(col))
if result.has_key(col):
result[col] += m[rowcount]
else:
result[col] = m[rowcount]
rowcount += 1
for key in result.keys():
k = result_prefix + str(key)
tmp = cmd_ctx.redis_master.lpop(k)
if tmp == None:
cmd_ctx.redis_master.rpush(k, result[key].dumps())
else:
cmd_ctx.redis_master.rpush(k, (result[key] + numpy.loads(tmp)).dumps())
示例14: data_from_pipeline
def data_from_pipeline(data, shape=None, dtype=None):
if len(shape) == 0:
return numpy.array(data, dtype=dtype)
else:
a = numpy.array([numpy.loads(x) for x in data], dtype=dtype)
a.shape = (-1,)+shape
return a
示例15: socket_cb2
def socket_cb2(socket,val):
global u1,running2,fr2
if val[0] == 's':
u1 = np.loads(val[1:])
fr2 += 1
elif val[0] == 'e':
running2 = False