小编Fir*_*man的帖子

为什么在 C++/Python/NumPy 中 log(inf + inf j) 等于 (inf + 0.785398 j)?

我一直在 C++ 和 numpy 中发现关于函数处理复杂无限数log的行为的奇怪行为。log具体来说,log(inf + inf * 1j)等于(inf + 0.785398j)我期望的值(inf + nan * 1j)

当取复数的对数时,实部是输入的绝对值的对数,虚部是输入的相位。返回 0.785398 作为 的虚部log(inf + inf * 1j)意味着它假设inf实部和虚部中的 s 具有相同的长度。这个假设似乎与其他计算不一致,例如 ,inf - inf == naninf / inf == nan假设 2 infs 不一定具有相同的值。

为什么假设log(inf + inf * 1j)不同?

重现 C++ 代码:

#include <complex>
#include <limits>
#include <iostream>
int main() {
    double inf = std::numeric_limits<double>::infinity();
    std::complex<double> …
Run Code Online (Sandbox Code Playgroud)

c++ python numpy infinity complex-numbers

55
推荐指数
3
解决办法
3943
查看次数

Tensorflow简单线性回归

我是机器学习和张量流的初学者.在尝试张量流的第一步中,我尝试了一个简单的多元线性回归.然而,似乎该模型陷入了局部最低限度.这是我的代码.

import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt

def weight_variable(shape):
    initial = tf.truncated_normal(shape, stddev=1)
    return tf.Variable(initial)

# dataset
xx = np.random.randint(0,1000,[1000,3])/1000.
yy = xx[:,0] * 2 + xx[:,1] * 1.4 + xx[:,2] * 3

# model
x = tf.placeholder(tf.float32, shape=[None, 3])
y_ = tf.placeholder(tf.float32, shape=[None])
W1 = weight_variable([3, 1])
y = tf.matmul(x, W1)

# training and cost function
cost_function = tf.reduce_mean(tf.square(y - y_))
train_function = tf.train.AdamOptimizer(1e-2).minimize(cost_function)

# create a session
sess = tf.Session()

# train …
Run Code Online (Sandbox Code Playgroud)

python regression linear-regression tensorflow

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