标签: repeat

根据计数的元素数组复制

我的问题是与此类似一个,但我想根据在相同尺寸的第二阵列指定的计数复制每个元素.

这方面的一个例子,比如我有一个数组v = [3 1 9 4],我想用它rep = [2 3 1 5]来复制第一个元素2次,第二次复制,依此类推[3 3 1 1 1 9 4 4 4 4 4].

到目前为止,我正在使用一个简单的循环来完成工作.这就是我的开始:

vv = [];
for i=1:numel(v)
    vv = [vv repmat(v(i),1,rep(i))];
end
Run Code Online (Sandbox Code Playgroud)

我设法通过预先分配空间来改进:

vv = zeros(1,sum(rep));
c = cumsum([1 rep]);
for i=1:numel(v)
    vv(c(i):c(i)+rep(i)-1) = repmat(v(i),1,rep(i));
end
Run Code Online (Sandbox Code Playgroud)

但是我仍然觉得必须有一个更聪明的方法来做到这一点......谢谢

arrays matlab repeat run-length-encoding elementwise-operations

8
推荐指数
1
解决办法
2926
查看次数

重复的组合

我正在使用Mathematica 7和一个combinatorica包函数我可以从一个元素列表获得一定数量的所有组合,其中顺序无关紧要且没有重复.eg:

in: KSubsets[{a, b, c, d}, 3]
out: {{a, b, c}, {a, b, d}, {a, c, d}, {b, c, d}}
Run Code Online (Sandbox Code Playgroud)

我无法找到一个功能,这将使我一定数目的所有组合从元素,其中的顺序并不重要,那里的名单重复的.即,上面的示例将在输出中包含{a,a,b},{a,a,a},{b,b,b}等元素.

它可能需要自定义功能.如果我能拿出一个,我会发一个答案但是现在我没有看到明显的解决方案.

编辑:理想情况下,输出将不包含组合的重复,例如元组[{a,b,c,d},3]将返回包含两个元素的列表,如{a,a,b}和{b,a,a从组合的角度来看,它们是相同的.

combinations wolfram-mathematica repeat

8
推荐指数
3
解决办法
4901
查看次数

Matlab - 通过多次合并相同的原始矢量来构建矩阵

是否有matlab功能允许我进行以下操作?

x = [1 2 2 3];

然后基于x我想构建矩阵m = [1 2 2 3; 1 2 2 3; 1 2 2 3; 1 2 2 3]

matlab tiling rows matrix repeat

8
推荐指数
1
解决办法
1万
查看次数

StateListDrawable和平铺位图

这是我的自定义选择器(StateListDrawable)

<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@drawable/common_cell_background" />
    <item
        android:state_pressed="true"
        android:drawable="@drawable/common_cell_background_highlight" />
    <item
        android:state_focused="true"
        android:drawable="@drawable/common_cell_background_highlight" />
    <item
        android:state_selected="true"
        android:drawable="@drawable/common_cell_background_highlight" />
</selector>
Run Code Online (Sandbox Code Playgroud)

common_cell_background和common_cell_background_highlight都是XML.代码如下:

common_cell_background.xml

<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/common_cell_background_bitmap"
    android:tileMode="repeat"
    android:dither="true">
</bitmap>
Run Code Online (Sandbox Code Playgroud)

common_cell_background_highlight.xml

<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/common_cell_background_bitmap_highlight"
    android:tileMode="repeat"
    android:dither="true">
</bitmap>
Run Code Online (Sandbox Code Playgroud)

位图也完全相同.亮点只是稍​​微轻一点,没有其他差异.两个位图都是PNG文件.

现在我开始了

convertView.setBackgroundResource(R.drawable.list_item_background);
Run Code Online (Sandbox Code Playgroud)

这是问题所在.我的common_cell_background没有重复,它已经拉长了.但是,当我触摸列表背景的单元格时,令人惊讶的是变为common_cell_background_highlight并猜测是什么?一切都很好,它应该像它应该重复.我不知道问题出在哪里,为什么我的背景不会重复突出显示.有什么想法吗?

xml android bitmap repeat statelist

8
推荐指数
1
解决办法
1751
查看次数

使用CSS3持续向上动画气泡?

见下图:

http://i.imgur.com/3vTrB.png

在后台查看那些透明圆圈?我想做的是让它们从下往上动画,然后手动跳下(屏幕外)并重新开始动画.圆圈是用于制作圆圈效果的简单<span>元素border-radius.

这可能与CSS3有关,还是我需要javascript?如果可能的话,我也会喜欢在向上移动时在X范围内随机移动圆圈.我会想象随机性需要javascript吗?

如果可能的话,我会很感激有关如何制作它的一些建议/想法.如果不能用CSS,Javascript库也是受欢迎的!

html5 continuous repeat css3 css-animations

8
推荐指数
1
解决办法
3万
查看次数

重复一段代码固定次数

我正在尝试重复一段代码,不使用条件,但仍然只重复特定次数.

基本上,这样的事情:

repeat(50)
{
    //Do stuff here.
}
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点?除了复制和粘贴50次?

我这样做是因为我想如果我知道有多少次我想重复一些事情,那么每次检查一个条件要快得多.那是准确的吗?或者我还会检查它重复了多少次?

基本上,它是否更快?

c++ performance repeat

8
推荐指数
1
解决办法
2万
查看次数

UserNotification在3天后重复每天/每小时 - iOS 10

UILocalNotification已被折旧,因此我想将我的代码更新为UserNotification框架:

let alertDays = 3.0
let alertSeconds = alertDays * 24.0 * 60.0 * 60.0

let localNotification:UILocalNotification = UILocalNotification()

localNotification.alertAction = "Reminder"
localNotification.alertTitle = "Reminder Title"
localNotification.alertBody = "Reminder Message"
localNotification.fireDate = Foundation.Date(timeIntervalSinceNow: alertSeconds)
localNotification.repeatInterval = .day            
UIApplication.shared().scheduleLocalNotification(localNotification)
Run Code Online (Sandbox Code Playgroud)

在等待初始通知后,如何使用UserNotification框架设置类似的每日或每小时重复?

let alertDays = 3.0
let alertSeconds = alertDays * 24.0 * 60.0 * 60.0

let content: UNMutableNotificationContent = UNMutableNotificationContent()

content.title = "Reminder Title"
content.subtitle = "Reminder Subtitle"
content.body = "Reminder Message"

let calendar = Calendar.current

let alarmTime = Foundation.Date(timeIntervalSinceNow: alertSeconds)
let …
Run Code Online (Sandbox Code Playgroud)

notifications date repeat swift ios10

8
推荐指数
1
解决办法
3174
查看次数

语法错误:关键字参数重复

我有以下查询集:

site_list = SiverifyVerificationSite.objects.filter(pattern_id=int(p_id), if_target=bundle.obj.pattern.if_target).exclude(ptrf__istartswith='ptrf-mt23run1-')
Run Code Online (Sandbox Code Playgroud)

如果我给出一个排除过滤器,它会起作用,而如果我在排除中包含第二个过滤器,它会抛出(语法错误:关键字参数重复)。理想情况下我想要的是:

site_list = SiverifyVerificationSite.objects.filter(pattern_id=int(p_id), if_target=bundle.obj.pattern.if_target).exclude(ptrf__istartswith='ptrf-mt23run1-', ptrf__istartswith='ptrf-20251-') 
Run Code Online (Sandbox Code Playgroud)

有没有运营商可以做这个。谢谢。

python django arguments repeat django-queryset

8
推荐指数
1
解决办法
3万
查看次数

在SceneKit中重复平面上的纹理

我有一个32x32 .png图像,我想通过SCNPlane重复.我得到的代码(见下文)导致图像被拉伸以适应平面的大小,而不是重复.

码:

let planeGeo = SCNPlane(width: 15, height: 15)

let imageMaterial = SCNMaterial()
imageMaterial.diffuse.contents = UIImage(named: "art.scnassets/grid.png")

planeGeo.firstMaterial = imageMaterial

let plane = SCNNode(geometry: planeGeo)

plane.geometry?.firstMaterial?.diffuse.wrapS = SCNWrapMode.repeat
plane.geometry?.firstMaterial?.diffuse.wrapT = SCNWrapMode.repeat
Run Code Online (Sandbox Code Playgroud)

xcode textures repeat swift

8
推荐指数
2
解决办法
4042
查看次数

正则表达式字符按照 grep 重复 n 次或更多次

我需要找到正则表达式来找到一个用 grep 重复 4 次或更多次的字符。

我知道表达式是 {n,},所以如果我需要查找行,例如,当字符“g”重复 4 次或更多次时,理论上 grep 手册页是:

grep "g{4,}" textsamplefile
Run Code Online (Sandbox Code Playgroud)

但不起作用。有什么帮助吗?

字符可以有其他字母。例如,有效匹配是:

g示例g of g有效g匹配g

g其他g有效g匹配gg这里g

GGGG其他

regex grep repeat

8
推荐指数
1
解决办法
1万
查看次数