我有一个点列表,它们是 kmeans 算法的惯性值。
为了确定最佳集群数量,我需要找到这条曲线开始变平的点。
数据示例
以下是我的值列表的创建和填充方式:
sum_squared_dist = []
K = range(1,50)
for k in K:
km = KMeans(n_clusters=k, random_state=0)
km = km.fit(normalized_modeling_data)
sum_squared_dist.append(km.inertia_)
print(sum_squared_dist)
Run Code Online (Sandbox Code Playgroud)
我怎样才能找到一个点,这条曲线的节距增加(曲线正在下降,所以一阶导数为负)?
我的方法
derivates = []
for i in range(len(sum_squared_dist)):
derivates.append(sum_squared_dist[i] - sum_squared_dist[i-1])
Run Code Online (Sandbox Code Playgroud)
我想使用肘部方法找到任何给定数据的最佳聚类数。有人可以帮助我如何找到惯性值列表开始变平的点吗?
编辑数据点
:
[7342.1301373073857, 6881.7109460930769, 6531.1657905495022,
6356.2255554679778, 6209.8382535595829, 6094.9052166741121,
5980.0191582610196, 5880.1869867848218, 5779.8957906367368,
5691.1879324562778, 5617.5153566271356, 5532.2613232619951,
5467.352265375117, 5395.4493783888756, 5345.3459908298091,
5290.6769823693812, 5243.5271656371888, 5207.2501206569532,
5164.9617535255456]
Run Code Online (Sandbox Code Playgroud)
我有一个角度的提要服务,它调用一个REST端点,该端点返回EntryDTO列表。服务外观如下:
@Injectable({providedIn: 'root'})
constructor(private http: HttpClient) {}
export class FeedService() {
getPublicFeedEntries: Observable<EntryDTO[]> () {
return this.http.get('/rest/publicFeedEntries/).map((response: Response) => response.json()).catch((err: any) => Observable.throw(error.josn().error || 'error');
}
}
Run Code Online (Sandbox Code Playgroud)
因此,我可以拥有一个订阅此可观察值的提要组件:
export class FeedComponent() {
private feedEntries: EntryDTO[];
constructor(private feedService: FeedService) { feedEntries = new Array(); }
ngOnInit() {
this.feedService.getPublicFeedEntries.subscribe(entries => {
this.feedEntries = entries;
}, err => {console.log(err) })
}
}
Run Code Online (Sandbox Code Playgroud)
这是否被视为在服务中返回可观察对象并订阅组件的最佳实践,还是还有其他最佳实践?
我有以下代码:
public List<Entry> getEntriesForUserId(int userId) {
User u = DataBaseConnector
.getAllUsers()
.stream()
.filter(user -> user.getUserId() == userId)
.findFirst()
.orElse(new User(-1, "Error");
return u.getEntries();
}
Run Code Online (Sandbox Code Playgroud)
getEntries()返回一个List<Entry>.
如何将return语句添加到此lambda表达式中?有点像
.map(User::getEntries)?
给定一个 HTML:
<div class="class">1</div>
<div class="class">2</div>
<div class="class">3</div>
<div class="class">4</div>
Run Code Online (Sandbox Code Playgroud)
我知道我可以display:flex一起做:
.class :nth-child(1) { order: 2 }
.class :nth-child(2) { order: 4 }
.class :nth-child(3) { order: 1 }
.class :nth-child(4) { order: 3 }
Run Code Online (Sandbox Code Playgroud)
这应该产生
<div class="class">3</div>
<div class="class">1</div>
<div class="class">4</div>
<div class="class">2</div>
Run Code Online (Sandbox Code Playgroud)
有没有办法在不将 flexbox 与其 order 属性结合使用的情况下做到这一点?
我有一个使用 JDK8 开发的 SpringBoot 应用程序,现在已移植到 JDK11。我在启动时收到以下异常:
ERROR SpringApplication: Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'groovyMarkupConfigurer' defined in class path resource [org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration$GroovyMarkupConfiguration.class]: Invocation of init method failed; nested exception is java.lang.reflect.InaccessibleObjectException: Unable to make jdk.internal.loader.ClassLoaders$AppClassLoader(jdk.internal.loader.ClassLoaders$PlatformClassLoader,jdk.internal.loader.URLClassPath) accessible: module java.base does not "opens jdk.internal.loader" to unnamed module @2e3967ea
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:140)
at de.ff.jf.bftag.alarmmonitor.Main.main(Main.java:38) …Run Code Online (Sandbox Code Playgroud) 我正在运行我自己的 prestashop 主题并想添加一个没有 css 的新页面。因此我添加了三个文件 php、controller 和 template。我将 php 放在我的 prestashop 的根目录中,将控制器添加到 root/controllers/front 并将模板放在 root/themes/my-theme 中。
如果我调用http://localhost/prestashop/?page=custom-page,我会看到索引起始页,如果我调用 localhost/prestashop/custom-page,我会得到一个 HTTP 404。
有人可以帮我获取我的页面显示?
PHP:
<?php
include(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();
include(dirname(__FILE__).'/header.php');
$smarty->display(_PS_THEME_DIR_.'custom-page.tpl');
include(dirname(__FILE__).'/footer.php');
Run Code Online (Sandbox Code Playgroud)
控制器:
public function init(){
parent::init();
}
public function initContent(){
parent::initContent();
$this->setTemplate(_PS_THEME_DIR_.'custom-page.tpl');
}
//public function setMedia(){
//parent::setMedia();
//$this->addCSS(_THEME_CSS_DIR_.'custom-page.css');
//$this->addJS(_THEME_JS_DIR_.'custom-page.js');
//}
Run Code Online (Sandbox Code Playgroud)
}
模板:
<div>
HELLO PAGE
</div>
{literal}
<style type="text/css">
</style>
{/literal}
<script type="text/javascript">
{literal}
{/literal}
</script>
Run Code Online (Sandbox Code Playgroud) 我有以下 HTML 结构:
<div class="products-container">
{foreach from=$cart.products item=product}
<div class="product" data-id-product="{$product.id_product}" data-id-product-attribute="{$product.id_product_attribute}">
...
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
现在我有一个可以删除任何 div 的javascript .product。
有没有办法将已删除的 div 从 DOM 右侧淡出并为其他 div 设置动画“向上移动到可用空间”?
我有以下HTML/CSS/JS:
<div id="blockcart-wrapper">
<div class="blockcart cart-preview">
<div class="header">
<a rel="nofollow" href="#">
<img class="cart-icon" src="https://via.placeholder.com/20x20" onclick="toggleClass()">
</a>
</div>
<div class="body" id="shopping-cart-body">
<div class="close"><a href="" onclick="toggleClass()">X</a></div>
<ul>
</ul>
<div class="shopping-cart-header">CART</div>
<div class="products-container">
<div class="product">
<span class="prodcut-image"><img src="https://via.placeholder.com/250x100"></span>
<div class="product-details">
<div class="name-header">This is a very long test name</div>
<div class="product-quantity-details">
<span class="quantity">QTY</span>
<span class="color-circle"></span>
<span class="color">COLOR</span>
</div>
<div class="price-open">
<span class="product-price">XX.XX</span>
<span class="product-link"><a href="#">open</a></span>
</div>
</div>
</div>
</div>
<div class="checkout">
<div class="taxes">
<span class="label">Taxes</span>
<span class="value">0</span>
<hr>
</div>
<div class="cart-total">
<span class="label">Total</span>
<span …Run Code Online (Sandbox Code Playgroud) 我对一个寻呼机的基本布局很感兴趣.
这是我的代码:
section {
position: relative;
height: 100vh;
}
.section-single>.arrow {
position: absolute;
left: 50%;
bottom: 10%;
}
.section-double>.content-left {
width: 50%;
float: left;
background: gray;
}
.section-double>.content-right {
width: 50%;
float: left;
background: black;
}
#section1 {
background: green;
}
#section2 {
background: red;
}
#section3 {
background: yellow;
}Run Code Online (Sandbox Code Playgroud)
<section class="section-single" id="section1">
<iframe src="https://www.youtube.com/watch?..."></iframe>
<a href="#section2"><span class="arrow">section 2</span></a>
</section>
<section class="section-double" id="section2">
<div class="content-left" id="div1">
</div>
<div class="content-right" id="div2">
</section>
<section class="section-double" id="section3">
<div class="content-left" id="div3">
</div>
<div …Run Code Online (Sandbox Code Playgroud)我有以下HTML / CSS
.cart-preview .body {
visibility: hidden;
position: fixed;
width: 400px;
height: 100%;
z-index: 99;
background-color: #fff;
right: -20;
}
.cart-preview:hover .body {
visibility: visible;
position: fixed;
transition: right 1s linear;
right: 0;
}Run Code Online (Sandbox Code Playgroud)
<div class="body">
<ul>
</ul>
<div class="cart-subtotals">
<div class="products">
<span class="label">Subtotal</span>
<span class="value">0</span>
</div>
<div class="">
<span class="label"></span>
<span class="value"></span>
</div>
<div class="shipping">
<span class="label">Shipping</span>
<span class="value">0</span>
</div>
<div class="">
<span class="label"></span>
<span class="value"></span>
</div>
</div>
<div class="cart-total">
<span class="label">Total sum</span>
<span class="value">0</span>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
我想让 …
我有以下 HTML/CSS,其中有一个.full-width.section3具有绝对高度的容器 ( )。然而,将内容居中是行不通的。由于我是 Flex 模型的新手,有人可以向我解释一下,为什么三个 childdiv不垂直居中?
body {
margin:0;
}
.container {
display:flex;
flex-wrap:wrap;
height:100vh;
background-color: white;
}
.full-width {
width:100%;
}
.full-width.section3{
height: 795px;
}
.full-width > .content > .third-parent{
height: 100%;
display: flex;
}
.full-width > .content > .third-parent > .third{
position: relative;
flex: 1 1 0px;
width: 100%;
border: 1px solid black;
}
.full-width > .content > .third-parent > .third > img{
position: absolute;
width: 100%;
height: auto;
left: 50%;
top:50%;
visibility: …Run Code Online (Sandbox Code Playgroud)我有以下代码将图像从相机保存到磁盘:
public static Image getAndSaveImage(int imageCount)
{
var image = _camera.GetImage() as ThermalImage;
image.Palette = PaletteManager.Iron;
_camera.GetImage().EnterLock();
Image camImage = _camera.GetImage().Image;
_camera.GetImage().ExitLock();
camImage.Save("./images/picture" + Convert.ToString(imageCount) + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
return camImage;
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我将图像保存到文件中.目前,在循环内调用此方法.我想用websocket替换保存到磁盘,因此客户端可以连接到此套接字并从底层流接收位图图像.由于位图是一个数组,这应该工作,不应该吗?
我在一些文件中读到我可以使用该TcpListener课程.所以我会做以下事情:
TcpListener server = new TcpListener(IPAddress.Parse("127.0.0.1"), 80);
server.Start();
TcpClient client = server.AcceptTcpClient();
NetworkStream stream = client.GetStream();
Run Code Online (Sandbox Code Playgroud)
如何将我的位图图像写入此流,以便另一方的python客户端可以获取图像?我是否需要自己处理TCP握手?
非常感谢
我有代码片段(HTML/CSS/JavaScript/jQuery).问题是关于<ul>与items-list正确的div中的类与类list-div.
我设法为整个列表设置动画,但是,我试图为每个列表项设置动画以在其结束位置飞行.我知道我可以使用带有延迟动画的简单jQuery
var delay = 0;
$("#list-to-animate li").each(function() {
$(this).delay(delay).animate({"top" : "+=30px"}, "fast");
delay += 200;
});
Run Code Online (Sandbox Code Playgroud)
但这不适用于我检查元素是否实际出现在屏幕上的整个JavaScript.
我也在努力解决如何li正确定位元素,因此它们不在list-div.
有人可以帮助我按照li现在整个列表的方式设置动画,所以连续飞行吗?
PS:我不确定嵌入式视频是否有效,如果不是只是向下滚动.
$(document).on('click', 'a[href^="#"]', function (event) {
//prevent direct jump to the linked element
event.preventDefault();
$('html, body').animate({
scrollTop: $($.attr(this, 'href')).offset().top
}, 500);
});
var slideIndex = 0;
// run TWO slideshows, one for each slider
showSlides(0);
showSlides(1);
// give your slider function parameter of index
function showSlides(index) {
var …Run Code Online (Sandbox Code Playgroud)css ×7
html ×6
java ×2
angular ×1
angular6 ×1
c# ×1
css-position ×1
data-science ×1
flexbox ×1
groovy ×1
java-8 ×1
java-stream ×1
javascript ×1
layout ×1
list ×1
numpy ×1
prestashop ×1
python ×1
scikit-learn ×1
spring-boot ×1