numpy.ones_like(a, dtype=None, order='K', subok=True)返回和原矩阵一样形状的1矩阵
-
Return an array of ones with the same shape and type as a given array.
Parameters: a : array_like
The shape and data-type of a define these same attributes of the returned array.
dtype : data-type, optional
Overrides the data type of the result.
New in version 1.6.0.
order : {‘C’, ‘F’, ‘A’, or ‘K’}, optional
Overrides the memory layout of the result. ‘C’ means C-order, ‘F’ means F-order, ‘A’ means ‘F’ if a is Fortran contiguous, ‘C’ otherwise. ‘K’ means match the layout of a as closely as possible.
New in version 1.6.0.
subok : bool, optional.
If True, then the newly created array will use the sub-class type of ‘a’, otherwise it will be a base-class array. Defaults to True.
Returns: out : ndarray
Array of ones with the same shape and type as a.
See also
- zeros_like
- Return an array of zeros with shape and type of input.
- empty_like
- Return an empty array with shape and type of input.
- zeros
- Return a new array setting values to zero.
- ones
- Return a new array setting values to one.
- empty
- Return a new uninitialized array.
Examples
>>>>>> x = np.arange(6)
>>> x = x.reshape((2, 3))
>>> x
array([[0, 1, 2],
[3, 4, 5]])
>>> np.ones_like(x)
array([[1, 1, 1],
[1, 1, 1]])>>>>>> y = np.arange(3, dtype=np.float)
>>> y
array([ 0., 1., 2.])
>>> np.ones_like(y)
array([ 1., 1., 1.])
- © Copyright 2008-2009, The Scipy community.
- Last updated on Oct 18, 2015.
- Created using Sphinx 1.2.1.
numpy.ones_like(a, dtype=None, order='K', subok=True)返回和原矩阵一样形状的1矩阵的更多相关文章
- numpy.zeros(shape, dtype=float, order='C')
numpy.zeros Return a new array of given shape and type, filled with zeros. Parameters: shape : int o ...
- numpy.ones(shape, dtype=None, order='C')
Return a new array of given shape and type, filled with ones. Parameters: shape : int or sequence of ...
- pig询问top k,每个返回hour和ad_network_id最大的两个记录(SUBSTRING,order,COUNT_STAR,limit)
pig里面有一个TOP功能.我不知道为什么用不了.有时间去看看pig源代码. SET job.name 'top_k'; SET job.priority HIGH; --REGISTER piggy ...
- np.asarray(a, dtype=None, order=None)
np.asarray(a, dtype=None, order=None) 参数a:可以是,列表, 列表的元组, 元组, 元组的元组, 元组的列表,多维数组 参数dtype=None, order=N ...
- 一个N*M的矩阵,找出这个矩阵中所有元素的和不小于K的面积最小的子矩阵
题目描述: 一个N*M的矩阵,找出这个矩阵中所有元素的和不小于K的面积最小的子矩阵(矩阵中元素个数为矩阵面积) 输入: 每个案例第一行三个正整数N,M<=100,表示矩阵大小,和一个整数K 接下 ...
- Numpy 数组和dtype的一个使用误区
首先自定义三种类型(如下代码1-3行),第一行使用scalar type,第2,3行使用Structured type. 提出问题:第5,7行同为创建数组,为什么第5行能work,而第7行会raise ...
- 给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行。
从第0行开始,输出第k行,传的参数为第几行,所以在方法中先将所传参数加1,然后将最后一行加入集合中返回. 代码如下: public static List<Integer> generat ...
- 编写函数digit(num, k),函数功能是:求整数num从右边开始的第k位数字的值,如果num位数不足k位则返回0。
function digit(num,k){ var knum = 0; for(var i=1; i<=k; i++){ knu ...
- php 数据库查询order by 与查询返回的数据类型
<?php /** * Created by PhpStorm. * User: DY040 * Date: 2017/11/24 * Time: 9:40 * * 从结果集合中读取一行数据 * ...
随机推荐
- 数组中去除重复的对象的简单方法and&&的使用
const arr = [ { name:'tom', age:15 }, { name:'rose', age:17 }, { name:'tom', age:11 }, { name:'rose' ...
- 数据库抽象层PDO
通过数据库抽象层PDO可以访问多个数据库 //数据库抽象层PDO //造DSN:驱动名:dbname=数据库名:host=服务器地址 $dsn = "mysql:dbname=mydb;ho ...
- c的详细学习(7)指针学习(一)
指针是c语言的一个重要概念,指针类型是c语言最有特色的数据类型: *利用指针编写的程序可使调用函数共享变量或数据结构,实现双向数据通信: *可以实现内存空间的动态存储分配:可以提高程序的编译效率和执行 ...
- windows与VMware ubuntu虚拟机实现文件共享
本文基本摘自:无限挑战者的博客 本人用的系统是win10系统,应该区别不大,实现的是win10系统和VMWare虚拟机Ubantu系统之间的文件共享.到网上找了很多的方法各种各样的方式,由于对Linu ...
- 【leetcode刷题笔记】Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 解题:设定一个变量 ...
- UI控制滑杆插件
在线演示 本地下载
- Idea中配置Tomcat7的JNDI
1.进入目录 D:\apache-tomcat-7.0.73\conf\Catalina\localhost 添加hello.xml ,内容为: <Context path="/hel ...
- Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found 问题排查
自定义的classLoader启动spring容器,遇到 Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not subtype ...
- Echarts 地图(map)插件之 省份的颜色自定义
ECharts,缩写来自Enterprise Charts,商业级数据图表,一个纯Javascript的图表库,可以流畅的运行在PC和移动设备上,兼容当前绝大部分浏览器(IE6/7/8/9/10/11 ...
- Mysql存储过程及调用
存储过程: 存储过程是SQL 语句和可选控制流语句的预编译集合,以一个名称存储并作为一个单元处理.存储过程存储在数据库内,可由应用程序通过一个调用执行,而且允许用户声明变量.有条件执行以及其它强大的 ...