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. 深入ConcurrentHashMap二

    深入ConcurrentHashMap一,已经介绍了主要的ConcurrentHashMap的结构,Segment组成,HashEntry的组成以及包含ConcurrentHashMap的创建. 这篇 ...

  2. [转载]Hibernate如何提升数据库查询的性能

    目录(?)[-] 数据库查询性能的提升也是涉及到开发中的各个阶段在开发中选用正确的查询方法无疑是最基础也最简单的 SQL语句的优化 使用正确的查询方法 使用正确的抓取策略 Hibernate的性能优化 ...

  3. java基础入门之九九乘法表

    /* 自学java 九九乘法表 Power by Stuart Date: 2015.4.23 */public class Math { public static void main (Strin ...

  4. Java注释Override、Deprecated、SuppressWarnings

    在J2SE5.0的java.lang包中预定义了三个注释:Override.Deprecated和SuppressWarnings Override 这个注释的作用是标识某一个方法是否覆盖了它的父类的 ...

  5. Iptalbes练习题(一)

    实验环境: KVM 虚拟机 centos6.7 test1:192.168.124.87  test2:192.168.124.94 场景一: 要求:1.对所有地址开放本机的tcp(80.22.10- ...

  6. iOS 动态修改导航栏颜色 UINavigationBar

    示例 所谓动态修改  意思是 在当前页面滚动的过程中 亦或 是在 触发返回事件\进入一个新的页面  导航栏的动态变化 由于系统级别的navBar 高度集成  很多自己想实现的功能 很不好弄 如果是通过 ...

  7. P4045 [JSOI2009]密码

    题目 P4045 [JSOI2009]密码 做法 AC自动机+状压+爆搜 建AC自动机是显然的,顺便预处理\(lst_i\)表示\(i\)结点以哪些串结束(二进制) 然后跑状压\(dp[i][j][k ...

  8. form memory cache、form disk cache与304

    200 from memory cache 不访问服务器,直接读缓存,从内存中读取缓存.此时的数据时缓存到内存中的,当kill进程后,数据将不存在200 from disk cache 不访问服务器, ...

  9. [算法]旋转矩阵问题(Spiral Matrix)

    题目一: Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spir ...

  10. 分享知识-快乐自己:Shrio 案例Demo概述

    Shiro 权限认证核心: POM:文件: <!--shiro-all--> <dependency> <groupId>org.apache.shiro</ ...