np.array函数详解--NumPy 零基础教学|全程手写代码

NumPy-核心函数np.array()深入解析 NumPy为Python提供了高效的多维数组对象以及一系列用于处理这些数组的工具,极大地简化了数值计算的过程。而np.array()作为NumPy库的核心函数之一,是创建和操作数组的基础 阅读详情

哔哩哔哩numpy教程持续更新

numpy信息

import numpy as np

# # 查看版本号
print(np.__version__)
# 查看配置
np.show_config()
2.2.6
Build Dependencies:
  blas:
    detection method: pkgconfig
    found: true
    include directory: C:/Users/runneradmin/AppData/Local/Temp/cibw-run-7xf_vzet/cp310-win_amd64/build/venv/Lib/site-packages/scipy_openblas64/include
    lib directory: C:/Users/runneradmin/AppData/Local/Temp/cibw-run-7xf_vzet/cp310-win_amd64/build/venv/Lib/site-packages/scipy_openblas64/lib
    name: scipy-openblas
    openblas configuration: OpenBLAS 0.3.29  USE64BITINT DYNAMIC_ARCH NO_AFFINITY
      Haswell MAX_THREADS=24
    pc file directory: C:/a/numpy/numpy/.openblas
    version: 0.3.29
  lapack:
    detection method: pkgconfig
    found: true
    include directory: C:/Users/runneradmin/AppData/Local/Temp/cibw-run-7xf_vzet/cp310-win_amd64/build/venv/Lib/site-packages/scipy_openblas64/include
    lib directory: C:/Users/runneradmin/AppData/Local/Temp/cibw-run-7xf_vzet/cp310-win_amd64/build/venv/Lib/site-packages/scipy_openblas64/lib
    name: scipy-openblas
    openblas configuration: OpenBLAS 0.3.29  USE64BITINT DYNAMIC_ARCH NO_AFFINITY
      Haswell MAX_THREADS=24
    pc file directory: C:/a/numpy/numpy/.openblas
    version: 0.3.29
Compilers:
  c:
    commands: cl
    linker: link
    name: msvc
    version: 19.29.30159
  c++:
    commands: cl
    linker: link
    name: msvc
    version: 19.29.30159
  cython:
    commands: cython
    linker: cython
    name: cython
    version: 3.1.0
Machine Information:
  build:
    cpu: x86_64
    endian: little
    family: x86_64
    system: windows
  host:
    cpu: x86_64
    endian: little
    family: x86_64
    system: windows
Python Information:
  path: C:\Users\runneradmin\AppData\Local\Temp\build-env-r6iiznem\Scripts\python.exe
  version: '3.10'
SIMD Extensions:
  baseline:
  - SSE
  - SSE2
  - SSE3
  found:
  - SSSE3
  - SSE41
  - POPCNT
  - SSE42
  - AVX
  - F16C
  - FMA3
  - AVX2
  not found:
  - AVX512F
  - AVX512CD
  - AVX512_SKX
  - AVX512_CLX
  - AVX512_CNL
  - AVX512_ICL

​

numpy.array

numpy.array(object, dtype = None, copy = True, order = None, subok = False, ndmin = 0)

object 数组或嵌套的数列
dtype 数组元素的数据类型,可选
copy 对象是否需要复制,可选
order 创建数组的样式,C为行方向,F为列方向,A为任意方向(默认)
subok 默认返回一个与基类类型一致的数组
ndmin 指定生成数组的最小维度

# 1维数组
list01 = [1,2,3]
a = np.array([1,2,3])
b = np.array(list01)
a,b
(array([1, 2, 3]), array([1, 2, 3]))
# 元祖
tup01 =(1,2,3)
a = np.array((1,2,3))
b = np.array(tup01)
a,b
(array([1, 2, 3]), array([1, 2, 3]))
#嵌套

my_arr = np.array(  [[1,2,3],[4,5,6]]  )
print(type(my_arr))
print(my_arr)
<class 'numpy.ndarray'>
[[1 2 3]
 [4 5 6]]
# dtype = complex 创建虚数 数组
a = np.array([1,  2,  3], dtype = complex)
a
array([1.+0.j, 2.+0.j, 3.+0.j])

dtype设置数组中数字的类型

  • bool_ 布尔型数据类型(True 或者 False)
  • int_ 默认的整数类型(类似于 C 语言中的 long,int32 或 int64)
  • intc 与 C 的 int 类型一样,一般是 int32 或 int 64
  • intp 用于索引的整数类型(类似于 C 的 ssize_t,一般情况下仍然是 int32 或 int64)
  • int8 字节(-128 to 127)
  • int16 整数(-32768 to 32767)
  • int32 整数(-2147483648 to 2147483647)
  • int64 整数(-9223372036854775808 to 9223372036854775807)
  • uint8 无符号整数(0 to 255)
  • uint16 无符号整数(0 to 65535)
  • uint32 无符号整数(0 to 4294967295)
  • uint64 无符号整数(0 to 18446744073709551615)
  • float_ float64 类型的简写
  • float16 半精度浮点数,包括:1 个符号位,5 个指数位,10 个尾数位
  • float32 单精度浮点数,包括:1 个符号位,8 个指数位,23 个尾数位
  • float64 双精度浮点数,包括:1 个符号位,11 个指数位,52 个尾数位
  • complex_ complex128 类型的简写,即 128 位复数
  • complex64 复数,表示双 32 位浮点数(实数部分和虚数部分)
  • complex128 复数,表示双 64 位浮点数(实数部分和虚数部分)
    *
  • int8, int16, int32, int64 四种数据类型可以使用字符串 ‘i1’, ‘i2’,‘i4’,‘i8’ 代替
a = np.array([[1,  2],  [3,  4]],dtype=np.int8)
b = type(a)
a,b
(array([[1, 2],
        [3, 4]], dtype=int8),
 numpy.ndarray)
x = np.array([[1, 2], [3, 4]],dtype=np.float64)
x
array([[1., 2.],
       [3., 4.]])
# np.astype(): 转换数组的数据类型
vec_1 = np.array(['1','2','3'])
vec_2 = vec_1.astype('float')
print("转换前的类型:",vec_1.dtype)
print(vec_1)
print("转换后的类型:",vec_2.dtype)
print(vec_2)
转换前的类型: <U1
['1' '2' '3']
转换后的类型: float64
[1. 2. 3.]

ndmin

作用

  • 指定输出数组最少有多少维。

  • 如果输入数据维度 < ndmin:在 shape 最前面补若干个长度为 1 的维度,把维度抬高到ndmin;

  • 如果输入数据维度 ≥ ndmin:数组保持原样,不做修改。

  • 默认值:ndmin=0

# 输入标量 10
a0 = np.array(10, ndmin=0)
a1 = np.array(10, ndmin=1)
a2 = np.array(10, ndmin=2)
a3 = np.array(10, ndmin=3)

print("ndmin=0:", a0.shape)   # ()  0维(标量)
print("ndmin=1:", a1.shape)   # (1,) 1维
print("ndmin=2:", a2.shape)   # (1,1) 2维
print("ndmin=3:", a3.shape)   # (1,1,1) 3维
ndmin=0: ()
ndmin=1: (1,)
ndmin=2: (1, 1)
ndmin=3: (1, 1, 1)
# 示例 2:一维列表

arr1 = np.array([1,2,3], ndmin=2)
print(arr1)
print("shape:", arr1.shape)  # (1, 3) 前面补1
[[1 2 3]]
shape: (1, 3)
# 示例 3:输入维度已经大于 ndmin,不会变化
# 输入本身是2维数组,ndmin=1 < 2,不变化
arr2 = np.array([[1,2],[3,4]], ndmin=1)
print(arr2.shape) # (2, 2)
(2, 2)

order:内存存储顺序

  • ‘C’ C 顺序(行优先):内存按行存放,一行行往内存写。numpy 默认。
  • ‘F’ Fortran 顺序(列优先):内存按列存放,一列列往内存写。
  • 只是改变元素在内存里面怎么排,肉眼打印看不出区别,体现在 .flags、ravel()、reshape()、性能上。
    *
data = [[1,2],
        [3,4]]

ac = np.array(data, order='C')
af = np.array(data, order='F')
# C_CONTIGUOUS=True:内存行优先连续存储(C 顺序)
# F_CONTIGUOUS=True:内存列优先连续存储(Fortran 顺序)

print("=== order='C'数组 ===")
print(ac)
print("C连续?", ac.flags)
print("F连续?", ac.flags)
print("\n=== order='F'数组 ===")
print(af)
print("C连续?", ac.flags)
print("F连续?", ac.flags)

print("C顺序展平:", ac.flatten(order='C'))      # [1 2 3 4] 按行展平
print("F顺序展平:", af.flatten(order='F'))       # [1 3 2 4] 按列展平
=== order='C'数组 ===
[[1 2]
 [3 4]]
C连续?   C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False

F连续?   C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False

​

=== order='F'数组 ===
[[1 2]
 [3 4]]
C连续?   C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False

F连续?   C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False

C顺序展平: [1 2 3 4]
F顺序展平: [1 3 2 4]

subok 参数详解

  • subok=False(默认):永远返回原生 numpy.ndarray,子类实例会被强制转为普通 ndarray
  • subok=True:如果输入是 ndarray 的子类,则保留子类类型,返回子类对象,而不是强制变回基础 ndarray
  • 日常写普通数据分析几乎用不到 subok;只有你自己继承 ndarray 自定义数组类的时候才会用到。
import numpy as np

# 自定义数组类,继承 np.ndarray
class MyArray(np.ndarray):
    pass

# 创建 MyArray 子类实例
my_arr = np.array([1,2,3]).view(MyArray)
print(type(my_arr))
# <class '__main__.MyArray'>
<class '__main__.MyArray'>
# subok=False 默认情况(丢弃子类,返回普通 ndarray)

a1 = np.array(my_arr, subok=False)
print(type(a1))
# <class 'numpy.ndarray'>
# ✨子类 MyArray 丢失,强制变回基础 ndarray
<class 'numpy.ndarray'>
# subok=True:保留子类类型
a2 = np.array(my_arr, subok=True)
print(type(a2))
# <class '__main__.MyArray'>
# ✨保留原来的 MyArray 子类
<class '__main__.MyArray'>
【Python】【Numpy】np.ma.array()函数详解和运行示例 np.ma.array 是 NumPy 库中的一个函数,用于创建一个 Masked Array(带掩码的数组)。Masked Array 是一种特殊类型的数组,其中某些元素可能被标记为无效或缺失。在处理这些数组时,这些被标记为无效的元素将被忽略。 阅读详情

相关推荐

Numpy 生成array(包括numpy.random),array属性

np.array(x,dtype=)#dtype可省略 a = np.asarray(x,dytp=np.float64) #类似numpy.array np.ones(N,dtype=np.float64)#生成长度为N的一维全一ndarray np.ones_like(a)#shape,dtype与数组a一样的 np.zeros(N,dtype=np.float64) np.zeros_lik...

Sibyl_Lqq的笔记 1760

Numpy.array()详解 、np.array与np.asarray辨析、 np.array和np.ndarry的区别

记录一下numpy.array()的详细用法,以及与np.asarray()和np.ndarray()的区别。 目录 1. Numpy.array()详解 1.1 函数形式 1.2 参数详解 1.3 具体用法 2.Asarray和Array辨析 2.1 object对象是普通迭代序列时 2.2object对象是ndarray对象时 3.Numpy.ndarray() 1. ...

THEAQING 9万+

UE4入门实例17(Unreal制作卡通Post Process材质球)

效果展示 #1 创建Post Porcess材质球 #2 编写Shader功能 #3 设置场景区域内风格化渲染 #1 创建Post Porcess材质球 #2 编写Shader功能 创建基础效果 移除现有通道渲染 设置视图渲染范围 #3 设置场景区域内风格化渲染 #4 加群下载Shader源码:284105567 ...

Unity3d 攻城师一枚 1347

np.mat()函数与np.array()函数的辨析

写在前面 今天,在学习numpy的时候,偶然看到np.mat()函数,查了一下,也是生成矩阵,这里的mat与MATLAB中的很相似,所以在这里简单的记录一下np.mat()函数应该怎么使用,和numpy中的array()函数有什么区别? np.mat()的基本操作 常规操作 创建矩阵 访问数据 排序等 >>> m= np.mat([1,2,3]) #创建矩阵 >&gt...

Miracle8070 3万+

7-1 链式基数排序 (20 分)

7-1 链式基数排序 (20 分) 实现链式基数排序,待排序关键字n满足1≤n≤1000,最大关键字数位≤5。 输入样例: 第一行输入待排序个数n(1≤n≤1000),再输入n个数(n的数位≤5)。 10 278 109 63 930 589 184 505 269 8 83 输出样例: 输出每趟分配-收集后链表中的关键字,趟数为序列中最大值的数位(如样例中930的数位为3),每行结尾有空格。 930 63 83 184 505 278 8 109 589 269 505 8 109 930 63 26

OwemShu的博客 4240

飞书日历同步Outlook翻车?我踩过的坑和最终用Google Calendar成功的完整配置记录

本文详细记录了从Outlook日历同步到飞书时遇到的常见问题及解决方案,特别是通过Google Calendar实现稳定同步的完整配置流程。文章揭示了Outlook同步方案易翻车的原因,并提供了Google Calendar的避坑指南、高级技巧和企业级部署建议,帮助用户高效实现日历同步。

weixin_33724046的博客 315

【NumPy】一文向您详细介绍 np.array()

🔥【NumPy深度解析】一文带您领略np.array()的魅力!🌟 从基础到进阶,这篇文章带您揭开NumPy中np.array()的神秘面纱。我们不仅会探讨它的基本用法,还会深入挖掘其高级特性和扩展功能。通过对比np.array()与Python原生列表,您将领略到其高效与便捷。同时,我们还将探讨广播机制及其在数据分析中的应用,让您的数据处理更加得心应手。最后,总结篇将为您画龙点睛,助您轻松掌握np.array()的精髓!#NumPy #np.array() #数据分析 #广播机制 #高效处理

创作高质量博文,分享知识,共同进步! 7813

QT6与QT5安装全攻略:从下载到环境配置一站式指南

本文提供了一份详尽的QT6与QT5安装教程,涵盖从版本选择、在线安装器使用到环境变量配置的全过程。针对新手常见痛点,重点对比了QT6与QT5的安装差异,并给出了MinGW与MSVC编译器的选择建议,旨在帮助开发者快速搭建稳定可用的QT开发环境,避免常见错误。

weixin_29216353的博客 314

Numpy中的np.split()函数详解

np.split()函数详解 1.官方注释2.参数解释3.例子参考 NumPy(Numerical Python) 是 Python 语言的一个扩展程序库,支持大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库。np.split()函数的作用是将一个数组拆分为多个子数组,跟Tensorflow中的slice()函数有点类似,但是np.split()函数返回的是多个数组,tf.slic...

Kobaayyy的博客 1万+

MAPLAB X IDE仿真调试

一、开发环境 操作系统:Windows 10 调试工具:Pickit3 单片机型号:PIC24FJ32GA002 二、操作步骤 1、连接Pickit3仿真器于单片机对应的烧写口如图示: 2、点击调试项目进入调试模式,这时底下输出框显示"运行"代表成功进入调试模式。 3、选择断点,该IDE只支持两个断点,使用超过两个时,超过的断点亮灰色代表无效。设置好断点后需暂停然后再重新点击运行才能生效。可以看到在断点处有绿色光标。 ...

RealHero的博客 5086

EMB电子机械制动系统和EHB电子液压制动系统控制功能的对比

EMB电子机械制动系统相比EHB液压制动系统具有显著优势:响应速度更快(<100ms)、控制精度更高(±2N·m)、能实现单轮独立控制,支持0.1%级制动力调节。在ABS、ESC等安全功能上表现更优,制动平顺性和NVH性能更好,同时提升能量回收效率15%-20%。特别适合智能驾驶需求,可使AEB等系统响应时间缩短50ms,紧急制动距离减少1米以上。EMB系统完美契合高阶自动驾驶对快速响应和精准控制的要求。

m0_59012156的博客 889

numpy——np.array、np.matrix、np.mat的区别及(*)、np.multiply、np.dot乘法的区别

文章目录【1】np.array,np.matrix,np.mat的区别(1)数据类型不同(2)np.mat和np.matrix的区别【3】矩阵相乘 (*)、np.multiply、np.dot的区别(1)当被乘的二者为array时(2)当被乘的二者为mat/matrix时 【1】np.array,np.matrix,np.mat的区别 (1)数据类型不同 np.array产生numpy.ndarray类型的数据,不能进行矩阵意义上的乘法。np.matrix,np.mat产生numpy.matrix类型数据,

qq_46126258的博客 9396

IEC61850规约客户端软件开发实战(第六章)

IEC 61850标准中的GOOSE(Generic Object Oriented Substation Event,面向通用对象的变电站事件)功能是变电站自动化系统的核心通信机制,主要用于实现智能电子设备(IED)间高可靠性、低延时的实时信号传输。本章简述其核心功能与技术特点。

半青年的博客 1780

Numpy:np.array() 与 np.asarray()

1 np.array() np.array()的作用就是按照一定要求将object转换为数组。 numpy.array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0) 参数 含义 返回 object 必选参数,类型为array_like,可以有四种类型:数组,公开数组接口的任何对象,__array__方法返回数组的对象,或任何(嵌套)序列。 ndarray。满足指定要求的数组对象。 dty

weixin_40522801的博客 8177

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

【numpy】np.array和np.asarray区别

array和asarray都可将结构数据转换为ndarray类型。 但是主要区别就是当数据源是ndarray时,array仍会copy出一个副本,占用新的内存,但asarray不会。 一、输入都为列表 lst1=[[1,1,1],[1,1,1],[1,1,1]] arr2=np.array(lst1) arr3=np.asarray(lst1) lst1[1][1]=2 pri...

吾志所往,所向披靡 2953

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

Numpy || np.array()函数用法指南

numpy.array()函数基本用法,包括:(1)Numpy ndarray对象 (2)介绍numpy.array()函数的全部参数 (3)如何创建数组及数组副本 (4)数组元素类型转化 (5)多维数组序列长度不同时怎么处理 等

weixin_47097527的博客 3万+

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

【教程】实测np.fromiter 和 np.array 的性能

如何选择有依据了

xfxuezhang.cn 5119

(转)Python的numpy中np.split()与np.array_split()函数使用说明

转载来源Python | numpy | np.split()与np.array_split()函数 split(ary, indices_or_sections, axis=0) :把一个数组从左到右按顺序切分 参数: ary:要切分的数组 indices_or_sections:如果是一个整数,就用该数平均切分,如果是一个数组,为沿轴切分的位置(左开右闭) axis:沿着哪个维度进行切向,默认为0,横向切分。为1时,纵向切分 ### 关于np.split()函数

小米n416的博客 4897

python 数组生成 numpy.array np.array np.asarray 简介

) for instantiating an array.【1-使用array(), zeros()或empty()方法:数组应该使用array, zeros()或empty()构造。3 4')”,就是子类,是矩阵类型。3 4'))中subok为False,返回的数组类型被强制为基类数组,所以DYX的类型是<class 'numpy.ndarray'>,是数组;必选参数,类型为array_like,可以有四种类型:数组,公开数组接口的任何对象,__array__方法返回数组的对象,或任何(嵌套)序列。

whatday的专栏 2215

np.split()与np.array_split()函数 | Numpy | Python

np.split() 均等分割,不均等会报错 np.array_split() 不均等分割,不会报错 ### 关于np.split()函数 x = np.arange(9) #9行1列的列向量 print(x, np.shape(x)) y = np.split(x, 3) # 平均分成三份,不能平均的话则会报错 print(y) y = np.split(x, 3, axis=0) # 平均分成...

kudou1994的博客 3974

np.array()

1.np.array构造函数 np.array([1,2,3,4,5]) ///一维数组 np.array([1,2,3],[2,3,4])///二维数组 1.1 numpy array 和 python list 有什么区别? Python中提供了list容器,可以当作数组使用。但列表中的元素可以是任何对象,因此列表中保存的是对象的指针,这样一来,为了保存一个简单的列表[1,2,3]。就需要三个指针和三个整数对象。对于数值运算来说,这种结构显然不够高效。 1.2 如何强制生成一个 float 类型的数组

Candyerer的博客 9460

Numpy np.array 相关常用操作学习笔记

Numpy np.array 相关常用操作学习笔记 1.np.array构造函数 用法:np.array([1,2,3,4,5]) 1.1 numpy array 和 python list 有什么区别? 标准Python的列表(list)中,元素本质是对象。如:L = [1, 2, 3],需要3个指针和三个整数对象,对于数值运算比较浪费内存和CPU。因此,Numpy提供了nda...

low米的博客 909

Numpy.array()详解

1. Numpy.array()详解 该函数的作用一言蔽之就是用来产生数组。 1.1 函数形式 numpy.array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0) 1.2 参数详解 object:必选参数,类型为array_like,可以有四种类...

devil_son1234的博客 8655

Python中Numpy的np.array详解

np.array 用于创建一个新的NumPy数组对象

weixin_64123373的博客 5664

numpy常用函数详解

在深度神经网络代码中经常用到numpy库的一些函数,很多看过之后很容易忘记,本文对经常使用的函数进行归纳总结。

漫步者 1529
上一篇: pycharm 无法将“pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
下一篇: 彻底搞懂两台电脑在“不同网络“下完整通信全过程
王_teacher
博客等级 码龄9年 118粉丝 51原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值