NumPy基本操作(一)

学习笔记——Numpy基本操作(一) Numpy 介绍 NumPy(Numerical Python) 是 Python语言的一个扩展程序库,支持大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库。 NumPy的前身 Numeric 最早是由 Jim Hugunin 与其它协作者共同开发,2005年,Travis Oliphant 在 Numeric中结合了另一个同性质的程序库 Numarray 的特色,并加入了其它扩展而开发了 NumPy。NumPy 为开放源代码并且由许多协作者共同维护开发。 包括: 一个强大的 N 维数组对 阅读详情

相关知识

NumPy简介

NumPy是用Python进行科学计算的基本软件包。它包含以下内容:

  • 一个强大的N维数组对象
  • 复杂的(广播)功能
  • 用于集成C/C++和Fortran代码的工具
  • 有用的线性代数,傅里叶变换和随机数能力
  • 用于读写磁盘数据以及操作内存映射文件的工具

NumPy是一个用python实现的科学计算包。包括:1、一个强大的N维数组对象Array;2、比较成熟的(广播)函数库;3、用于整合C/C++和Fortran代码的工具包;4、实用的线性代数、傅里叶变换和随机数生成函数。numpy和稀疏矩阵运算包scipy配合使用更加方便。

NumPy(Numeric Python)提供了许多高级的数值编程工具,如:矩阵数据类型、矢量处理,以及精密的运算库。专为进行严格的数字处理而产生。多为很多大型金融公司使用,以及核心的科学计算组织如:Lawrence Livermore,NASA用其处理一些本来使用C++,Fortran或Matlab等所做的任务。

numpy的核心结构:ndarray(多维数组)

NumPy中创建数组的方法如下表:

NumPy.ndarray属性

NumPy.ndarray函数

 

1.打开终端模拟器,在命令行输入ipython notebook --ip='127.0.0.1',在浏览器中会打开jupyter界面,点击New,在其下拉框中选择Python3.

2.新建一个ipyt文件,用于编写并执行代码。

3.ndarray的属性

import numpy as np  
a=np.arange(15).reshape(3,5)  
a  
#使用shape查看a的形状  
a.shape  
#使用ndim查看a的维数  
a.ndim  
#使用dtype查看a的数据类型  
a.dtype.name  
#查看数组a的元素个数  
a.itemsize  
type(a)  

 

创建数组ndarray

4.array():将列表、元组转化成ndarray,使用array创建数组,数组的类型是由列表中元素的类型决定。

import numpy as np  
a=np.array([2,3,4])  
a  
#查看数组a的数据类型  
a.dtype  
b=np.array([1.2,3.5,5.1])  
#查看数组b的数据类型  
b.dtype  

 

5.使用array函数将元组转化成数组。

array1=np.array(((1,2,3),(2,3,4)))  
print(array1)  

 

6.array创建数组时,可以定义数据的类型

c=np.array([[1,2,3],[1.2,3.5,6]],dtype=np.float64)  
print(c)  

 

7.zeros():创建全为0的数组,使用zeros函数创建一个全为0的3行4列数组。

array_zeros=np.zeros((3,4))  
print(array_zeros)  

 

8.ones():创建全为1的数组,使用ones函数创建一个全是1的形状为(2,3,4)的3维数组,数据类型为int16.

array_ones=np.ones((2,3,4),dtype=np.int16)  
print(array_ones)  

 

9.empty():创建随机数组,使用empty函数创建一个形状为(2,3)的随机数组,它的元素值是随机的,以内存的状态决定。

array_empty=np.empty((2,3))  
print(array_empty)  

 

10.arange():创建的NumPy数组,使用Numpy中类似于range的函数arange,创建一个从10到30间

Numpy的基本操作(一) 前言导入创建简单数组指定数据元素数据类型np.下的属性创建数组对象numpy的其他用法np的特殊方法 前言 我们在学习Numpy之前需要了解Numpy是什么?能做什么! NumPy(Numerical Python) 是 Python 语言的一个扩展程序库,支持大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库。 导入 Numpy是一个第三方库,所以我们需要在python中导入,直接用import numpy 然后点击红色灯泡就可以导入。 我们可以使用import numpy as n. 阅读详情

相关推荐

Numpy学习笔记(一)基本操作&array的创建

文章目录前言一、基本操作1.引入库2.array创建数组3.获取array相关信息(维数,形状,元素数)二、array的创建1.引入库2.dtype设置数组的数据类型3.zeros创建全零数组4.ones创建全1数组5.empty创建全空数组6.arange创建连续数组7.reshape改变数组形状8.linespace创建连续数组 前言   这同样是我根据b站大佬莫烦的numpy库学习视频而整理的笔记,有时间可以前去观看 https://www.bilibili.com/video/BV1Ex41..

qq_40680007的博客 779

Python数据分析案例——宏观经济指标与沪深指数实证研究分析

沪深300指数与宏观经济指标关联性研究:2015-2024实证分析 摘要:本文基于2015-2024年月度数据,采用多元回归方法分析宏观经济指标对沪深300指数的影响。研究发现,市场情绪(SEN)、美国利率(STY)、美元指数(DXY)、狭义货币供应量(M1)和CPI对指数具有显著解释力(P<0.05),而GDP、LPR等传统指标影响不显著。模型解释力达62%(R²=0.62),表明A股短期走势更受资金流动、投资者心理和国际金融条件驱动。研究为投资者提供了除基本面外的市场预判指标,建议关注M1增速、美

weixin_50902344的博客 1404

HarmonyOS开发第一步:Dev Eco Studio4.0保姆级安装配置指南(含Node.js环境)

本文提供HarmonyOS开发环境搭建的保姆级教程,重点详解Dev Eco Studio 4.0的安装与配置,并攻克Node.js环境与Ohpm包管理器的关键设置难点。通过清晰的步骤指引,帮助开发者从零开始,高效完成开发环境部署,顺利迈出鸿蒙应用开发的第一步。

lake5的博客 569

【IIC通信】Chap.1(I2C)IIC通信原理、IIC读写时序详解

IIC通信以两根连线SDA、SCL实现了完善的全双工同步数据传送, 可以方便地构成多机系统和外围器件扩展系统。

Jie_MSD的博客 2万+

【同等学力】2004-数学⭐✨

1.有些人勤奋,但并非所有人都勤奋。2.不管白猫黑猫,抓住老鼠就是好猫

super_mochi1 511

计算机组成原理(第三版)唐朔飞-第一章第二章-课后习题

计算机组成原理

weixin_45735391的博客 7万+

TC3XX - MCAL知识点(三十七):AURIX™ TC3xx 的BootLoader烧录APP完成之后跳转使多个核均正常运行

摘要:针对AURIX TC3xx多核芯片在软件复位后仅Core0能启动的问题,分析发现该芯片在Cold Power-on Reset(断电复位)时会完整执行多核启动流程,而Application Reset(软件复位)会跳过从核初始化。解决方案包括:1)在BootLoader中显式调用IfxCpu_startCore()函数启动其他核;2)通过跳转函数强制各核从指定地址启动;3)双Boot场景下让每个核独立响应复位命令。实测表明,软件复位后需手动触发从核启动,或采用断电复位方式确保所有核正常初始化。

梦想技术家 411

Vite 任意文件读取漏洞复现(CVE-2026-39363)

Vite开发服务器 WebSocket中的fetchModule方法未实施server.fs访问控制,导致攻击者可通过WebSocket连接并读取服务器上的任意文件(CVE-2026-39363)

iSee857的博客 221

08-StarRocks性能调优FAQ

StarRocks性能调优摘要 本文提供了StarRocks数据库性能调优的常见问题解答,涵盖查询优化、索引设计、分区策略和系统配置等关键方面。主要内容包括:查询优化技巧(使用EXPLAIN分析、避免全表扫描、优化JOIN和聚合查询);索引选择与维护建议(高频查询列索引、复合索引);分区策略设计(时间分区、范围分区)及其管理方法;以及系统内存配置优化(JVM参数调整、查询内存限制设置)。这些优化措施可显著提升StarRocks的查询性能和系统效率。

欢迎来到我的博客,一起探索代码里的世界! 541

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

深度学习工具包 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")

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

上一篇: Jupyter notebook修改默认启动目录
下一篇: NumPy基本操作(二)
ITYTI
博客等级 码龄10年 30粉丝 42原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值