BP字符代码实现


import numpy as np
import scipy.io as scio
import matplotlib.pyplot as plt
import scipy.optimize as op

#显示图片数据
def displayData(X):
    m = np.size(X, 0)  #X的行数,即样本数量
    n = np.size(X, 1)  #X的列数,即单个样本大小
    example_width = int(np.round(np.sqrt(n)))  #单张图片宽度
    example_height = int(np.floor(n / example_width))  #单张图片高度
    display_rows = int(np.floor(np.sqrt(m)))  #显示图中,一行多少张图
    display_cols = int(np.ceil(m / display_rows))  #显示图中,一列多少张图片
    pad = 1  #图片间的间隔
    display_array = - np.ones((pad + display_rows * (example_height + pad),
                            pad + display_cols * (example_width + pad)))  #初始化图片矩阵
    curr_ex = 0  #当前的图片计数
    #将每张小图插入图片数组中
    for j in range(0, display_rows):
        for i in range(0, display_cols):
            if curr_ex >= m:
                break
            max_val = np.max(abs(X[curr_ex, :]))
            jstart = pad + j * (example_height + pad)
            istart = pad + i * (example_width + pad)
            display_array[jstart: (jstart + example_height), istart: (istart + example_width)] = \
                np.array(X[curr_ex, :]).reshape(example_height, example_width) / max_val
            curr_ex = curr_ex + 1
        if curr_ex >= m:
            break
    display_array = display_array.T
    plt.imshow(displa
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值