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.])

Previous topic

numpy.ones

Next topic

numpy.zeros

 
  • © 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矩阵的更多相关文章

  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 ...

  2. 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 ...

  3. 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 ...

  4. np.asarray(a, dtype=None, order=None)

    np.asarray(a, dtype=None, order=None) 参数a:可以是,列表, 列表的元组, 元组, 元组的元组, 元组的列表,多维数组 参数dtype=None, order=N ...

  5. 一个N*M的矩阵,找出这个矩阵中所有元素的和不小于K的面积最小的子矩阵

    题目描述: 一个N*M的矩阵,找出这个矩阵中所有元素的和不小于K的面积最小的子矩阵(矩阵中元素个数为矩阵面积) 输入: 每个案例第一行三个正整数N,M<=100,表示矩阵大小,和一个整数K 接下 ...

  6. Numpy 数组和dtype的一个使用误区

    首先自定义三种类型(如下代码1-3行),第一行使用scalar type,第2,3行使用Structured type. 提出问题:第5,7行同为创建数组,为什么第5行能work,而第7行会raise ...

  7. 给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行。

    从第0行开始,输出第k行,传的参数为第几行,所以在方法中先将所传参数加1,然后将最后一行加入集合中返回. 代码如下: public static List<Integer> generat ...

  8. 编写函数digit(num, k),函数功能是:求整数num从右边开始的第k位数字的值,如果num位数不足k位则返回0。

    function digit(num,k){         var knum = 0;         for(var i=1; i<=k; i++){                 knu ...

  9. php 数据库查询order by 与查询返回的数据类型

    <?php /** * Created by PhpStorm. * User: DY040 * Date: 2017/11/24 * Time: 9:40 * * 从结果集合中读取一行数据 * ...

随机推荐

  1. 【C语言】Linux C调用系统命令

    最近研究深度学习,做视频分析和检测,用到C语言,以前都是写python的,不过没关系,计算机语言都是相通的,差不多原理是一样的,只是语法不太一样. 下面介绍linux C语言种调用本地命令,访问一个地 ...

  2. R语言数据管理(五)

    一.数据的输入: 手动输入:edit( )函数 也可修改 mydata <- data.frame(age=numeric(0),gender=character(0),weight=numer ...

  3. 关于Unicode转为str的方法

    unicode_a=u'\u810f\u4e71' str_a=unicode_a.encode('unicode-escape').decode('string_escape')

  4. MYSQL:基础——事务处理

    MYSQL:基础——事务处理 事物处理 1.什么是事物处理 事务处理(transaction processing)可以用来维护数据库的完整性,它保证成批的MySQL操作要么完全执行,要么完全不执行 ...

  5. PHP-内嵌式语言(转)(未看)

    PHP,一个嵌套的缩写名称,是英文超级文本预处理语言(PHP:Hypertext Preprocessor)的缩写.PHP 是一种内嵌式的语言,PHP与微软的ASP颇有几分相似,都是一种在服务器端执行 ...

  6. 事务的四大特性ACID

    ACID是指数据库事务的四大特性,是由Jim Gray在19世纪70年代后期提出的概念,1983年Andreas Reuter and Theo Härder创造了ACID这个缩略语用来描述这四大特性 ...

  7. codeforces 57C 思维

    题意:求出长度为n仅由1到n数字组成的非降序列与非升序列的个数. 思路:转化为求非降序列(非升序列)的个数.n个元素想象为n个离散的点x1,x2,x3,...,xn,在最开头补上一个点x0为1,在最末 ...

  8. EntityFramework 学习 一 Eager Loading

    贪婪加载是指查询一个类型实体的时候同时查询与实体关联的类型 通过Include()方法实现 using (var context = new SchoolDBEntities()) { var stu ...

  9. 属性 visibility

    http://www.w3school.com.cn/cssref/pr_class_visibility.asp 可能的值 值 描述 visible 默认值.元素是可见的. hidden 元素是不可 ...

  10. 分享知识-快乐自己:PageHelper 分页关键基础代码

    关键代码:点我下载样式   详细介绍 //使用分页插件 jQuery("#pagination").pagination(data.total, { items_per_page: ...