我决定学习R.我试图了解如何编写"R风格"函数并避免循环.以下是一个示例情况:
给定一个向量a,我想计算一个向量,b其元素b[i](向量索引从1开始)定义如下:
1 <= i <= 4:
b[i] = NaN
5 <= i <= length(a):
b[i] = mean(a[i-4] to a[i])
Run Code Online (Sandbox Code Playgroud)
基本上,如果我们假装'a'是速度列表,其中第一个条目在时间= 0,第二个在时间= 1秒,第三个在时间= 2秒...我想获得相应的向量描述过去5秒的平均速度.
例如:如果a is (1,1,1,1,1,4,6,3,6,8,9)然后b应该是(NaN, NaN, NaN, NaN, 1, 1.6, 2.6, 3, 4, 5.4, 6.4)
我可以使用循环来做到这一点,但我觉得这样做不会是"R风格".
谢谢,
Tungata
我正在尝试使用Spring Security以编程方式验证用户登录/传递,因此我需要访问ProviderManager.我希望它能自动注入我的@Controller.
我的代码看起来像:
import org.springframework.security.authentication.ProviderManager;
// ...
@Controller
public class MyController {
@Autowired
private ProviderManager authenticationManager;
Run Code Online (Sandbox Code Playgroud)
但是当我尝试运行应用程序时,我收到以下错误消息:
No unique bean of type [org.springframework.security.authentication.ProviderManager] is defined:
expected single matching bean but found 2:
[org.springframework.security.authentication.ProviderManager#0, org.springframework.security.authenticationManager]
Run Code Online (Sandbox Code Playgroud)
可能是什么原因或我如何解决?
我使用Spring Security 3.0.0-RC1和Spring 3.0.1,我没有定义任何ProviderManagerbean.我成功使用了:
@Resource
private ProviderManager authenticationManager;
Run Code Online (Sandbox Code Playgroud)
在其他项目中,但javax.annotation.ResourceGAE不支持.
我正在尝试创建一个打印当前浏览器窗口的按钮.
这是我当前使用(或至少尝试使用)JSNI的代码:
private Button print = new Button(constants.print(), new ClickHandler() {
@Override
public void onClick(final ClickEvent event) {
/*-{
if ($wnd.print) {
$wnd.print();
return true;
} else {
return false;
}
}-*/
}
});
Run Code Online (Sandbox Code Playgroud)
但是当我点击按钮时,没有任何反应.这是我的第一个GWT应用程序,所以我不确定如何实现它.
我有一个自定义布局,在其子项下面绘制一个透明的圆角矩形.问题是当我尝试将其添加到我的xml文件时,它不会显示.此外,当我尝试向其添加参数时(即android:layout_width)弹出窗口显示它们都不可用.我添加的任何子视图都会发生同样的事情.有人可以帮忙吗?
public class RoundRectLayout extends LinearLayout
{
private RectF shape;
public RoundRectLayout(Context context)
{
super(context);
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.settings, this);
shape = new RectF();
}
public RoundRectLayout(Context context, AttributeSet attrs)
{
super(context, attrs);
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.settings, this);
shape = new RectF();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
shape = new RectF(0, 0, w - 5, h - 5);
super.onSizeChanged(w, h, oldw, oldh);
}
@Override
protected void dispatchDraw(Canvas canvas) …Run Code Online (Sandbox Code Playgroud) 有没有人使用GenericData.Record过Avro和嵌套的地图记录.给出以下架构,我正在努力填充GenericData.Record地图:
{"name": "log_data", "type":
[ "null",
{ "type": "map", "values":
{ "type": "record",
"name": "TypeValuePair",
"fields": [
{"name": "type", "type": "string"},
{"name": "value", "type": ["null", "string"]}
]
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
java代码:
Schema mapSchema = schema.getField("log_data").schema().getTypes().get(1);
//The code below fails
GenericRecord typeValuePair =
new GenericData.Record(mapSchema.getField("TypeValuePair").schema());
Run Code Online (Sandbox Code Playgroud)
有:
org.apache.avro.AvroRuntimeException: Not a record..
Run Code Online (Sandbox Code Playgroud)
知道我应该如何在avro架构中构建一个包含类型记录值的地图?
当我输入"node site.js"时我得到了这个,我100%确定我没有运行这个节点两次.
Error: listen EADDRINUSE :::3000
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at Server._listen2 (net.js:1262:14)
at listen (net.js:1298:10)
at Server.listen (net.js:1376:9)
at Server.listen.Server.attach (/root/node_modules/socket.io/lib/index.js:228:9)
at Timeout._onTimeout (/root/nodejs/site.js:1005:29)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
code: 'EADDRINUSE',
errno: 'EADDRINUSE',
syscall: 'listen',
address: '::',
port: 3000 }
Run Code Online (Sandbox Code Playgroud)
我正在使用FEDORA 23
我试图找到一种很好的方法来捕获一个距离给定字符串不超过N个字符的数字.
例如,如果字符串是"年龄"并且必须找到N = 4
"Age 5" => 5
"My age is 10 and I my name is John" => 10
"My age is almost 5 and I my name is Mary" => null
Run Code Online (Sandbox Code Playgroud)
在最后一种情况下,该数字与"年龄"分开超过4个字符.
public void setSRC(int var)
{
if (src== null)
{
src = new int[1];
src[0] = var;
}
else
{
int i = 0;
int[] temp = null;
temp = new int[src.length];
temp = src;
i = temp.length;
src = new int[i+1];
for (int j =0; j < temp.length ; j++)
src[j] = temp[j];
src[i] = var;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望使这个方法通用或模板方法.任何形式的帮助表示赞赏.期待它
好.这是一个问题.这是我的收藏:{2,3,4,2,3,5}.我们假设它List现在是一个.我想搜索这个系列的所有比赛'2'.我想索引相同.我知道,有indexOf()和lastIndexOf()的方法List和Arrays.binarySearch().但是,它们都返回一个元素,表示搜索元素的位置.有没有一种简单有效的方法来查找所有匹配项?请注意,此问题不仅限于原始类型.
在cpp文件中我有std :: round(double)
我能否知道Java中的等效代码
编辑:我已经java.lang.Math.round(double)在99%的情况下使用并获得匹配.但在某些地方我遇到了不匹配的问题.例如:
std::round(4816.5058) = 4816 和 Math.round(4816.5058) = 4817std::round(4466.49996) = 4467 和 Math.round(4466.49997) = 4466更新:我应该立即提到这一点:我首先考虑了Java/JSON映射框架,但我的经理不希望我向项目添加任何更多依赖项,因此这是一个选项.该JSON-Java的罐子已经在我们的类路径,这样我就可以使用,但仍然没有看到过的树木如何可以使用森林.
我的Java程序正在传递以下形式的JSON(虽然值会一直改变):
{"order":{"booze":"1","handled":"0","credits":"0.6",
"execute":0,"available":["299258"],"approved":[],
"blizzard":"143030","reviewable":["930932","283982","782821"],
"units":"6","pending":["298233","329449"],"hobbit":"blasphemy"}}
Run Code Online (Sandbox Code Playgroud)
我正在寻找从这个JSON字符串中挑选特定值的最简单,最有效,最可靠的方法,并将它们聚合成一个List<Long>.
具体来说,我正在寻找,提取和聚集所有"的IDS ",即,所有你看到的数字值available,approved,reviewable和pending领域.这些字段中的每一个都是0+"id"的数组.因此,在上面的示例中,我们看到了以下的ID细分:
available:有1个id(299258)approved:有0个IDreviewable:有3个ID(930932,283982,782821)pending:有2个ID(298233,329449)我需要一些Java代码来运行并生成一个List<Long>包含所有这6个提取的ID,没有特定的顺序.ID只需要将其列入列表即可.
这感觉就像一个非常复杂,复杂的正则表达式,我甚至不确定从哪里开始.任何帮助都非常感谢.提前致谢.