我知道在 SVG 中有两种方法可以将形状组合在一起并将它们定位为一个集合:嵌套<svg>标记和<g>分组。但是,我看不出它们之间有太大区别。例如,以下两段代码产生完全相同的结果:
使用组(jsfiddle):https : //jsfiddle.net/8q4on01m/5/
<svg width="5000" height="5000" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g transform="translate(200 200)">
<rect x="0" y="0" height="100" width="100" style="fill: yellow"></rect>
<rect x="0" y="0" height="100" width="100" style="fill: green" transform="rotate(45) translate(200 100)"></rect>
<rect x="0" y="0" height="100" width="100" style="fill: red" transform="translate(200 100)"></rect>
</g>
</svg>
Run Code Online (Sandbox Code Playgroud)
使用<svg> (jsfiddle):
<svg width="5000" height="5000" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<svg x="200" y="200">
<rect x="0" y="0" height="100" width="100" style="fill: yellow"></rect>
<rect x="0" y="0" height="100" width="100" style="fill: green" transform="rotate(45) translate(200 100)"></rect>
<rect x="0" …Run Code Online (Sandbox Code Playgroud) 我花了一些时间谷歌搜索并没有找到答案这个简单的问题:我如何映射Pandas数据帧的列?说,我有以下df:
In [67]: frame = pd.DataFrame(np.random.randn(4, 3), columns=list('bde'), index=['Utah', 'Ohio', 'Texas', 'Oregon'])
In [68]: frame
Out[68]:
b d e
Utah -1.240032 1.586191 -1.272617
Ohio -0.161516 -2.169133 0.223268
Texas -1.921675 0.246167 -0.744242
Oregon 0.371843 2.346133 2.083234
Run Code Online (Sandbox Code Playgroud)
我想为b列的每个值添加1 .我知道我可以那样做:
In [69]: frame['b'] = frame['b'].map(lambda x: x + 1)
Run Code Online (Sandbox Code Playgroud)
或类似的- AFAIK有没有什么区别map,并apply在上下文Series(除了map还可以接受dict或Series) -纠正我,如果我错了:
In [71]: frame['b'] = frame['b'].apply(lambda x: x + 1)
Run Code Online (Sandbox Code Playgroud)
但我不喜欢指定'b'两次.相反,我想做那样的事情:
frame['b'].map(lambda x: x + 1, …Run Code Online (Sandbox Code Playgroud) 以下代码无法编译:
def f[T](conv: Option[String => T]) {}
f(Some(_.toInt))
Run Code Online (Sandbox Code Playgroud)
同 <console>:13: error: missing parameter type for expanded function ((x$1) => x$1.toInt)
当然,显式类型使它很好:
scala> f(Some((x: String) => x.toInt))
Run Code Online (Sandbox Code Playgroud)
为什么编译器不能在这里推断字符串类型?有某种歧义吗?
通常,是否可以通过下划线扩展手动检查和检查生成的代码?
我觉得很奇怪
use std::sync::Arc;
trait Fruit {}
struct Pear {}
impl Fruit for Pear {}
fn main() {
let pear = Arc::new(Pear {});
let cloned = Arc::clone(&pear);
let cloned_casted: Arc<dyn Fruit> = cloned;
}
Run Code Online (Sandbox Code Playgroud)
编译,但是
use std::sync::Arc;
trait Fruit {}
struct Pear {}
impl Fruit for Pear {}
fn main() {
let pear = Arc::new(Pear {});
let cloned_casted: Arc<dyn Fruit> = Arc::clone(&pear);
}
Run Code Online (Sandbox Code Playgroud)
错误与
error[E0308]: mismatched types
--> main.rs:9:52
|
9 | let cloned_casted: Arc<dyn Fruit> = Arc::clone(&pear);
| ^^^^^ expected …Run Code Online (Sandbox Code Playgroud) 我正在Spring MVC中开发一个小的Web应用程序.每次我尝试在任何控制器中获取自定义类时,我都会得到异常,以防该类使用另一个自定义类.在示例中更容易显示:
控制器,我正在尝试获取自定义类WireTest的对象:
@Controller
@RequestMapping("/offices")
public class OfficesController {
@Autowired
private WireTest wt;
@RequestMapping("")
public String offices(Model model) {
model.addAttribute("test", wt.getString());
return "offices";
}
}
Run Code Online (Sandbox Code Playgroud)
无论我是直接创建对象还是使用@Autowired,问题总会发生.在这里的代码中,我展示了@Autowired的情况,但这没关系 - 我可以写private WireTest wt = new WireTest(),并且异常将是相同的.
WireTest.java 类:
@Service
public class WireTest {
public String getString() {return (DBhelper.getString());}
}
Run Code Online (Sandbox Code Playgroud)
部分DBhelper.java类(也有其他静态成员,完整代码如下):
public class DBhelper {
public static String getString() {return "Hi!";}
}
Run Code Online (Sandbox Code Playgroud)
例外情况:
HTTP Status 500 - Handler processing failed; nested exception is
java.lang.NoClassDefFoundError: Could not initialize class org.sher.wtpractice.dao.DBhelper
Run Code Online (Sandbox Code Playgroud)
我也可以在控制台应用程序中使用这些类而没有任何问题,因此它可以在Spring之外运行. …
有没有办法可以在scala中更快地计算上三角矩阵?
/** Returns a vector which consists of the upper triangular elements of a matrix */
def getUpperTriangle(A: Array[Array[Double]]) =
{
var A_ = Seq(0.)
for (i <- 0 to A.size - 1;j <- 0 to A(0).size - 1)
{
if (i <= j){
A_ = A_ ++ Seq(A(i)(j))
}
}
A_.tail.toArray
}
Run Code Online (Sandbox Code Playgroud) 我知道隐式转换可用于js.FunctionN<\xe2\x80\x93> scala.FunctionN。但是,如果我以动态方式使用库(没有类型化外观),它们将不会帮助我,因为编译器显然不知道我需要转换。例如,如果 JS 代码需要一个带有字符串和函数的 JS 数组作为输入——类似于
[\'Hello world\', function ($x, $y) {\n console.log($x + $y)\n}],\nRun Code Online (Sandbox Code Playgroud)\n\n,我无法像这样在 Scala 中创建它:
\n\n val a: js.Array[Any] = js.Array(\n "Hello world",\n (x: Int, y: Int) => {console.log(x + y)}\n )\n )\nRun Code Online (Sandbox Code Playgroud)\n\n因为Scala函数不会转换为JS函数。是否存在一些显式转换方法,类似于toJSArray可变 Seq?我已经检查过这asInstanceOf[js.Function]不起作用。