首页 \ 问答 \ 生成1D NumPy连续范围数组(Generate 1D NumPy array of concatenated ranges)

生成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

相关问答

更多
  • 你的问题是repeat-y会填满整个高度,无论你最初的位置在哪里。 因此,它与您的顶部和底部重叠。 一种解决方案是将重复背景推入位于容器顶部和底部12px的伪元素。 结果可以在这里看到 (演示中的不透明只是为了表明不存在重叠)。 没有不透明, 看到这里 。 相关代码(在CSS3浏览器中测试:IE9,FF,Chrome): CSS div { position: relative; z-index: 2; background: url(top.png) top left no-rep ...
  • 你可能想要使用CSS属性background-image (和速记background )而不是嵌入了图像的div。 这是一个简单的例子: HTML
    • Apples
    • Oranges
    • Bananas
    CSS li { height: 50px; padding-left: 60px; margin: 10px; background: url(http://placehold.i ...
  • 如果要一次选择多个DOM元素,请使用class属性: HTML: JS: var images = document.querySelectorAll(".thumb__cover"); 要么 var images = document.getElementsByClassName("thumb__cover"); 现在,images是一个nodeList ,可以包含任意数量的元素。 要为每个属性设置src属性,您必须遍历列表中的项目: ...
  • 哦,我的执行过程中遇到了很多问题。 主要问题:背景图像被“扭曲”,所以测量仪并非真正的圆形。 另外:代码有点搞砸了,太复杂了。 我在这里留下这个问题 - 也许这对未来的人有帮助。 protected void onDraw(Canvas canvas) { canvas.getClipBounds(bounds);+ //0.86 == Aspect Ratio of the Background gaugeBackground.setBounds(0, 0, bounds.righ ...
  • 如果您希望链接和图像“表现为一个”,则应使用javascript。 下面,我写了一个例子,说明它如何以非常简单的方式为链接和图像工作。 现场演示可以在JSFiddle: JSFiddle上获得 HTML:
  • 看起来好像图像的位置具有负左边距百分比。 这些在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 with t ...
  • 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. Then, ...
  • 您可能遇到了无效的标记 ,缺少的文档类型 ,或两者都有。 You're likely experiencing invalid markup, a missing doctype, or both.
  • 而不是将图像设置为背景图像,将它们设置为img元素:
  • 你必须绝对定位#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; }

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)