生成1D NumPy连续范围数组(Generate 1D NumPy array of concatenated ranges)

我想生成以下数组a

nv = np.random.randint(3, 10+1, size=(1000000,))
a = np.concatenate([np.arange(1,i+1) for i in nv])

因此,输出将是 - 像 -

[0, 1, 2, 3, 0, 1, 2, 3, 4, 0, 1, 2, 0, 1, 2, 3, 4, 5, 0, ...]

有没有更好的方法呢?


I want to generate a following array a:

nv = np.random.randint(3, 10+1, size=(1000000,))
a = np.concatenate([np.arange(1,i+1) for i in nv])

Thus, the output would be something like -

[0, 1, 2, 3, 0, 1, 2, 3, 4, 0, 1, 2, 0, 1, 2, 3, 4, 5, 0, ...]

Does there exist any better way to do it?


原文:https://stackoverflow.com/questions/41310119
2022-11-09 10:11

满意答案

你可能想要使用CSS属性background-image (和速记background )而不是嵌入了图像的div。

这是一个简单的例子:

HTML

<ul>
    <li>Apples</li>
    <li>Oranges</li>
    <li>Bananas</li>
</ul>

CSS

li {
    height: 50px;
    padding-left: 60px;
    margin: 10px;
    background: url(http://placehold.it/50x50) no-repeat;       
}​

演示


You're probably going to want to use the CSS property background-image (and the shorthand background) rather than a div with an image embedded in it.

Here is a simple example:

HTML

<ul>
    <li>Apples</li>
    <li>Oranges</li>
    <li>Bananas</li>
</ul>

CSS

li {
    height: 50px;
    padding-left: 60px;
    margin: 10px;
    background: url(http://placehold.it/50x50) no-repeat;       
}​

Demo

相关问答

更多

多个背景图像定位(Multiple background images positioning)

你的问题是repeat-y会填满整个高度,无论你最初的位置在哪里。 因此,它与您的顶部和底部重叠。 一种解决方案是将重复背景推入位于容器顶部和底部12px的伪元素。 结果可以在这里看到 (演示中的不透明只是为了表明不存在重叠)。 没有不透明, 看到这里 。 相关代码(在CSS3浏览器中测试:IE9,FF,Chrome): CSS div { position: relative; z-index: 2; background: url(top.png) top left n...

同一图像和定位的多个实例(Multiple instances of same image & positioning)

你可能想要使用CSS属性background-image (和速记background )而不是嵌入了图像的div。 这是一个简单的例子: HTML <ul> <li>Apples</li> <li>Oranges</li> <li>Bananas</li> </ul> CSS li { height: 50px; padding-left: 60px; margin: 10px; background: url(http://placeh...

多个随机图像旋转实例(Multiple instances of random image rotation)

如果要一次选择多个DOM元素,请使用class属性: HTML: <img class="thumb__cover" ... /> JS: var images = document.querySelectorAll(".thumb__cover"); 要么 var images = document.getElementsByClassName("thumb__cover"); 现在,images是一个nodeList ,可以包含任意数量的元素。 要为每个属性设置src属性,您必须遍历列表...

DrawArc上的图像,定位问题(DrawArc on image, positioning issue)

哦,我的执行过程中遇到了很多问题。 主要问题:背景图像被“扭曲”,所以测量仪并非真正的圆形。 另外:代码有点搞砸了,太复杂了。 我在这里留下这个问题 - 也许这对未来的人有帮助。 protected void onDraw(Canvas canvas) { canvas.getClipBounds(bounds);+ //0.86 == Aspect Ratio of the Background gaugeBackground.setBounds(0, 0, bounds...

在图像上定位超链接(Positioning hyperlink over an image)

如果您希望链接和图像“表现为一个”,则应使用javascript。 下面,我写了一个例子,说明它如何以非常简单的方式为链接和图像工作。 现场演示可以在JSFiddle: JSFiddle上获得 HTML: <ul id="content-images"> <li><img id="image1" class="show2" src="http://placehold.it/100x100" width="176" height="168"></li> </ul> <span id="link1" ...

IE图像定位问题(IE Image Positioning Issue)

看起来好像图像的位置具有负左边距百分比。 这些在IE中可能会有问题。 也许尝试使用蓝色背景将图标相对地放置在div内部,或者如果适用于您的布局则使用绝对定位。 Looks as if the images are positioned with negative left margin percentages. These can be problematic in IE. Maybe try positioning the icons relatively inside of the div w...

SSRS定位图像(SSRS positioning of an image)

AFAIK,无法直接进行自动对齐/对接。 对于我的报告,我将报告大小设置为适合标准纸张大小。 然后,如果我知道图像的大小,则很容易以静态方式定位它。 如果这对您不起作用,则可以使用自定义代码和元素填充 。 请看这个链接 。 HTH。 AFAIK, it is not possible to directly do auto-align / docking. For my reports, I set the report size to fit in a standard paper size. ...

使用绝对定位来解决问题(Getting around using Absolute Positioning)

您可能遇到了无效的标记 ,缺少的文档类型 ,或两者都有。 You're likely experiencing invalid markup, a missing doctype, or both.

使用Bootstrap进行图像定位(Image positioning using Bootstrap)

而不是将图像设置为背景图像,将它们设置为img元素: <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/> <div class="row"> <div class="col-md-8 img-container"> <img class="img-responsive" src="http://placehold.it/1000x...

定位由svg屏蔽的多个图像(positioning multiple images that are masked by an svg)

你必须绝对定位#img1Masked和#img2Masked。 #img1Masked, #img2Masked { position: absolute; top: 0; left: 0; } You have to absolute positioning #img1Masked and #img2Masked. #img1Masked, #img2Masked { position: absolute; top: 0; left: 0; }

相关文章

更多

3d引擎列表

免费引擎 Agar - 一个高级图形应用程序框架,用于2D和3D游戏。 Allegro lib ...

java3d的前景

奥运后一直在找工作,本来是做WEB方面的工作。 就像北京今天的天气一样,最近IT也是冷的要命。 工 ...

JOGL 处理3D图形

GLAutoDrawable&nbsp

Phaser开源2d引擎 javascript/html5游戏框架

原文来自:http://html6game.com/thread-1023-1-1.shtml 转自: ...

大芒果单机版魔兽世界GM命令d

命令: .modify hp 9999999 9999999增加被选择人物的血量 .modify ...

About Unity3D 4.1.2 (to continue…)

Here are something that need to take care of when y ...

想开发3D引擎

想制作3D引擎,希望高手给推荐一本好书。 需要什么IDE? 需要什么语言?JAVA/C++/C#. ...

Python内建函数(D)

dir([object]) 说明:不带参数时,返回当前范围内的变量、方法和定义的类型列表;带 ...

3D音频理论研究(二)---3D全介绍(转)

作者:it168.com Reny 一、3D音效   随着软、硬件的不断发展,传统的双声道单层面立体声 ...

Autodesk Map 3D 2012 新功能介绍

如果你看过以前的文章欧特克Autodesk发布基础设施2012系列产品, 你会了解到Map 3D 20 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本