小编Hen*_*nry的帖子

使用多处理库在同一个类中运行并发进程

我需要与'multiprocessing'库并行运行多个类函数,但我无法找到针对我的具体问题的指南或答案.我的问题是只有第一个进程正在启动(或运行我不知道这里的确切区别).

为了说明这个问题,我设置了以下示例:

import multiprocessing
import time

class parallel_printer(multiprocessing.Process):

    def __init__(self, freq_0, freq_1, freq_2):
        self.freq_0 = freq_0
        self.freq_1 = freq_1
        self.freq_2 = freq_2

    def print_0(self):
        while True:    
            now = time.localtime()
            if now.tm_sec % self.freq_0 == 0:
                print('printer 0')
                time.sleep(1.0)

    def print_1(self):
        while True:    
            now = time.localtime()
            if now.tm_sec % self.freq_1 == 0:
                print('printer 1')
                time.sleep(1.0)

    def print_2(self):
        while True:    
            now = time.localtime()
            if now.tm_sec % self.freq_2 == 0:
                print('printer 2')
                time.sleep(1.0)

    def start_printer(self):

        p_0 = multiprocessing.Process(target = self.print_0())
        p_1 = multiprocessing.Process(target …
Run Code Online (Sandbox Code Playgroud)

python multithreading python-3.x

2
推荐指数
1
解决办法
57
查看次数

最小化 Tensorflow 中的多元函数

假设我有以下几个变量函数的简单示例

@tf.function
def f(A, Y, X):
  AX = tf.matmul(A, X)
  norm = tf.norm(Y - AX)
  return norm

N = 2
A = tf.Variable(np.array([[1, 2], [3, 4]]))
Y = tf.Variable(np.identity(N))
X = tf.Variable(np.zeros((N, N)))
Run Code Online (Sandbox Code Playgroud)

我如何找到TensorflowX最小化?f我对一种通用解决方案感兴趣,该解决方案可与上面声明的函数一起使用,并且当有多个变量需要优化时。

python tensorflow

1
推荐指数
1
解决办法
2695
查看次数

标签 统计

python ×2

multithreading ×1

python-3.x ×1

tensorflow ×1