本文整理汇总了Python中numpy.loads函数的典型用法代码示例。如果您正苦于以下问题:Python loads函数的具体用法?Python loads怎么用?Python loads使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loads函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:AlexanderFillbrunn,项目名称:RedisML,代码行数:31,代码来源:matrix.py
示例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()
开发者ID:michaellas,项目名称:streaming-vid-to-gifs,代码行数:25,代码来源:service.py
示例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()
开发者ID:RoshanPasupathy,项目名称:3d_localisation,代码行数:58,代码来源:mprecvmaintest.py
示例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
)
开发者ID:sma-wideband,项目名称:phringes_sw,代码行数:10,代码来源:sma.py
示例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()
开发者ID:ReedAnders,项目名称:pyNeuralNetwork,代码行数:33,代码来源:RNNRBM.py
示例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
开发者ID:RoshanPasupathy,项目名称:3d_localisation,代码行数:13,代码来源:receivermain.py
示例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
开发者ID:RoshanPasupathy,项目名称:3d_localisation,代码行数:13,代码来源:receivermain.py
示例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
开发者ID:stefanoborini,项目名称:apptools,代码行数:13,代码来源:state_pickler.py
示例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)
开发者ID:andrzejkokoszka,项目名称:TiRT1,代码行数:7,代码来源:outputService.py
示例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)
开发者ID:avzahn,项目名称:hdtest,代码行数:33,代码来源:hdtest5.py
示例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)
开发者ID:maciej112,项目名称:StreamingVideo,代码行数:25,代码来源:save_video_service.py
示例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)
开发者ID:se4u,项目名称:genrich,代码行数:30,代码来源:tag_rhmm.py
示例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())
开发者ID:AlexanderFillbrunn,项目名称:RedisML,代码行数:31,代码来源:commands.py
示例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
开发者ID:tiagocoutinho,项目名称:bliss,代码行数:7,代码来源:channel.py
示例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
开发者ID:RoshanPasupathy,项目名称:3d_localisation,代码行数:7,代码来源:TCPTEST.py
示例16: run
def run(self):
video_input = self.get_input("videoInput")
video_output = self.get_output("videoOutput")
objects_input = self.get_input("objectsInput")
debug_output = self.get_output("debugOutput")
with open('config.json') as data_file:
data = json.load(data_file)
classes = data["conf"]["classes"]
frame = None
while self.running(): #pętla główna usługi (wątku głównego obsługującego strumień wideo)
frame_obj = video_input.read() #odebranie danych z interfejsu wejściowego
frame = np.loads(frame_obj) #załadowanie ramki do obiektu NumPy
objects = objects_input.read()
size_objects = len(objects)
for i in range(0,size_objects):
o = objects[i]
object_class = "class" + str(o[3])
color = classes[object_class]
cv2.rectangle(frame, (o[0], o[1]), (o[0]+o[2], o[1]+o[2]), (color[0],color[1],color[2]), 3)
#cv2.rectangle(frame, (20, 20), (100, 100), (0,255,0), 3)
video_output.send(frame.dumps())
debug_output.send([])
开发者ID:HAL90000,项目名称:tirt,代码行数:32,代码来源:picasso.py
示例17: socket_cb
def socket_cb(socket,val):
global u2,running1,fr1
if val[0] == 's':
u2 = np.loads(val[1:])
fr1 += 1
elif val[0] == 'e':
running1 = False
开发者ID:RoshanPasupathy,项目名称:3d_localisation,代码行数:7,代码来源:TCPTEST.py
示例18: 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") #obiekt interfejsu wyjściowego
while self.running(): #pętla główna usługi
try:
frame_obj = video_input.read() #odebranie danych z interfejsu wejściowego
except Exception as e:
video_input.close()
video_output.close()
break
frame = np.loads(frame_obj) #załadowanie ramki do obiektu NumPy
with self.filters_lock: #blokada wątku
current_filters = self.get_parameter("filtersOn") #pobranie wartości parametru "filtersOn"
if 1 in current_filters: #sprawdzenie czy parametr "filtersOn" ma wartość 1, czyli czy ma być stosowany filtr
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) #zastosowanie filtru COLOR_BGR2GRAY z biblioteki OpenCV na ramce wideo
frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR) # by można było zapisać jako obraz kolorowy
if 2 in current_filters:
frame = cv2.blur(frame,(7,7))
if 3 in current_filters:
frame = cv2.GaussianBlur(frame,(5,5),0)
if 4 in current_filters:
frame = cv2.medianBlur(frame,9) ## nieparzysta liczba
video_output.send(frame.dumps()) #przesłanie ramki za pomocą interfejsu wyjściowego
开发者ID:maciej112,项目名称:StreamingVideo,代码行数:29,代码来源:filter_video_service.py
示例19: clientthread
def clientthread(conn, L):
#Sending message to connected client
#conn.send('Welcome to the server. Type something and hit enter\n') #send only takes string
#infinite loop so that function do not terminate and thread do not end.
while True:
#Receiving from client
buf = b''
while len(buf) < 4:
buf += conn.recv(4 - len(buf))
length = struct.unpack('>I', buf)[0]
data = b''
l = length
while l > 0:
d = conn.recv(l)
l -= len(d)
data += d
if not data: break
M = np.loads(data) # HERE IS AN ERROR
if i == 1:
L = M
else:
L += M
# t0 = time.time()
# data_out = pickle.dumps(L)
# print("done in %fs" % (time.time() - t0))
# conn.sendall(data_out)
conn.close()
return(L)
开发者ID:potockan,项目名称:Text-clustering-basing-on-string-metrics,代码行数:35,代码来源:server2.py
示例20: import_ConvergenceTest
def import_ConvergenceTest(fn):
with open(fn) as f:
l = f.read()
c = eval(l)
for mode in c.result:
for arr in c.result[mode]:
c.result[mode][arr] = np.loads(c.result[mode][arr])
return c
开发者ID:johntyree,项目名称:fd_adi,代码行数:8,代码来源:convergence.py
注:本文中的numpy.loads函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论