from mxnet import nd
from time import time
a = nd.ones(shape=1000)
b = nd.ones(shape=1000)
start = time()
c = nd.zeros(shape=1000)
for i in range(1000):
c[i] = a[i]+b[i]
time() - start
start = time()
d = a + b
time() - start
a = nd.ones(shape=3)
b = 10
a + b
#代码从这里开始,上面是简单的练习----------------------------------------------------------
%matplotlib inline
from IPython import display
from matplotlib import pyplot as plt
from mxnet import autograd, nd
import random
num_inputs = 2
num_examples = 1000
true_w = [2, -3.4]
true_b = 4.2
features = nd.random.normal(scale=1,shape=(num_examples, num_inputs))
labels = true_w[0] * features[:,0] + true_w[1] * features[:,1] + true_b
labels += nd.random.normal(scale=0.01, shape=labels.shape)
features[0],labels[0]
def use_svg_display():
# 用矢量图显示
display.set_matplotlib_formats('svg')
def set_figsize(figsize=(3.5, 2.5)):
use_svg_display()
# 设置图的尺寸
plt.rcParams['figure.figsize
线性回归(2)从零开始实现
最新推荐文章于 2025-05-12 15:05:06 发布