例如,我有1维向量的维度(5).我想将其重塑为2D矩阵(1,5).
这是我如何用numpy做的
>>> import numpy as np
>>> a = np.array([1,2,3,4,5])
>>> a.shape
(5,)
>>> a = np.reshape(a, (1,5))
>>> a.shape
(1, 5)
>>> a
array([[1, 2, 3, 4, 5]])
>>>
Run Code Online (Sandbox Code Playgroud)
但是我怎么能用Pytorch Tensor(和Variable)做到这一点.我不想切换回numpy并再次切换到Torch变量,因为它会丢失反向传播信息.
这就是我在Pytorch中所拥有的
>>> import torch
>>> from torch.autograd import Variable
>>> a = torch.Tensor([1,2,3,4,5])
>>> a
1
2
3
4
5
[torch.FloatTensor of size 5]
>>> a.size()
(5L,)
>>> a_var = variable(a)
>>> a_var = Variable(a)
>>> a_var.size()
(5L,)
.....do some calculation in forward function
>>> a_var.size()
(5L,) …Run Code Online (Sandbox Code Playgroud) 我在github和Facebook开发者文档上阅读了该文档.
只有样品,仅此而已.没有API文件.
制作图谱API请求的代码是
const infoRequest = new GraphRequest(
'/me',
null,
this._responseInfoCallback,
);
Run Code Online (Sandbox Code Playgroud)
和回调
_responseInfoCallback(error: ?Object, result: ?Object) {
if (error) {
alert('Error fetching data: ' + error.toString());
} else {
alert('Success fetching data: ' + result.toString());
}
}
Run Code Online (Sandbox Code Playgroud)
这是制作图谱API请求的功能
testRequestGraphAPI(){
const infoRequest = new GraphRequest(
'/me',
null,
this._responseInfoCallback,
);
new GraphRequestManager().addRequest(infoRequest).start();
}
Run Code Online (Sandbox Code Playgroud)
但是,我找不到任何进一步的文件.我不知道每个参数做什么.
但是,当我尝试将'\ me'修改为'me?fields = id,name'时,它失败了.虽然我已经要求许可了
<LoginButton
publishPermissions={["publish_actions,user_birthday, user_religion_politics, user_relationships, user_relationship_details, user_hometown, user_location, user_likes, user_education_history, user_work_history, user_website, user_managed_groups, user_events, user_photos, user_videos, …Run Code Online (Sandbox Code Playgroud) 当我运行交互式spark-shell时,我会显示spark版本(2.2.0)和scala版本(2.11.8)
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 2.2.0
/_/
Using Scala version 2.11.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_131)
Run Code Online (Sandbox Code Playgroud)
但是,我想查看我使用Zeppelin(localhost)的Spark和Scala版本
我不确定Zeppelin是否使用我的交互式shell运行相同的spark/scala.
(我检查了https://community.hortonworks.com/questions/54918/how-do-i-tell-which-version-ofspark-i-am-running.html,但这不是我想要的,因为我主持了Zeppelin本地主机)
我设法使用这些代码获取export.realm
package com.meow.meowmeow;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.net.Uri;
import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import io.realm.Realm;
import io.realm.RealmConfiguration;
/**
* Created by Thien on 9/1/2015.
*/
public class RealmTool {
private static String LOG_TAG = "RealmTool";
//export to email
public static void exportDatabase(Context context,RealmConfiguration configuration) {
// init realm
Realm realm = Realm.getInstance(configuration);
File exportRealmFile = null;
try {
// get or create an "export.realm" file
exportRealmFile = new …Run Code Online (Sandbox Code Playgroud) 我正在绘制泰坦尼克号数据集的相关矩阵。
df_corr = df.corr()
Run Code Online (Sandbox Code Playgroud)
最初,矩阵如下所示:
fig = ff.create_annotated_heatmap(
z=df_corr.to_numpy(),
x=df_corr.columns.tolist(),
y=df_corr.index.tolist(),
zmax=1, zmin=-1,
showscale=True,
hoverongaps=True
)
# add title
fig.update_layout(title_text='<i><b>Correlation not round</b></i>')
Run Code Online (Sandbox Code Playgroud)
我想四舍五入浮点数,因此它们在.点后显示较少的数字。
当前的解决方法实际上是在输入之前围绕 pandas 数据框。
df_corr_round = df_corr.round(3)
fig = ff.create_annotated_heatmap(
z=df_corr_round.to_numpy(),
x=df_corr.columns.tolist(),
y=df_corr.index.tolist(),
zmax=1, zmin=-1,
showscale=True,
hoverongaps=True
)
# add title
fig.update_layout(title_text='<i><b>Correlation round</b></i>')
Run Code Online (Sandbox Code Playgroud)
但是当我将鼠标悬停在上面时,解决方法也会使文本四舍五入。我想要完整详细的悬停文本,而显示文本是圆形的。
我可以在不更改输入数据框的情况下在每个单元格上显示更少的数字吗?
我的输入文件在PasteBin上.
我目前的图表代码是:
#Input and data formatting
merg_agg_creek<-read.table("merged aggregated creek.txt",header=TRUE)
library(ggplot2)
library(grid)
source("http://egret.psychol.cam.ac.uk/statistics/R/extensions/rnc_ggplot2_border_themes.r")
CombinedCreek<-data.frame(merg_agg_creek)
Combined<-CombinedCreek[order(CombinedCreek[,2]),]
Combined$Creek <- factor(rep(c('Culvert Creek','North Silcox','South Silcox','Yucca Pen'),c(32,57,51,31)))
Combined$Creek<-factor(Combined$Creek,levels(Combined$Creek)[c(1,4,3,2)])
#The Graph Code
creek <-ggplot(Combined,aes(Month,Density,color=factor(Year),shape=factor(Year)))+scale_color_discrete("Year")+scale_shape_discrete("Year")
creek<-creek + facet_grid(Creek~. ,scales = "free_y")
creek <- creek + geom_jitter(position = position_jitter(width = .3))
creek<-creek+scale_color_grey("Year",end=.6)+theme_bw()
creek<-creek+scale_y_continuous(expression("Number of prey captured " (m^2) ^-1))
creek<-creek+opts( panel.border = theme_L_border() )+ opts(axis.line = theme_segment())
creek<-creek+opts(panel.grid.minor = theme_blank())+opts(panel.grid.major = theme_blank())
creek<-creek+scale_x_discrete("Month",breaks=c(2,5,8,11),labels=c("February","May","August","November"))
creek
Run Code Online (Sandbox Code Playgroud)
结果图是:
图

我的问题是,通过在"scale_x_discrete"中创建中断和标签,在图的右侧,12月的数据和构面标签之间存在较大的间隙.我尝试通过在"scale_x_discrete:"命令中添加"limits = c(0,13)"来消除这种差距,但结果图会破坏x标签.
如何消除这种差距?我的剧情创作中是否存在根本缺陷?
谢谢!
编辑:Didzis回答了下面的问题.我只需要从scale_x_discrete更改为scale_x_continuous
我阅读了关于cv2.createTrackbar的文档。它说
onChange – 每次滑块改变位置时要调用的函数的指针。这个函数的原型应该是 void Foo(int,void*); ,其中第一个参数是轨迹栏位置,第二个参数是用户数据(参见下一个参数)。如果回调是 NULL 指针,则不会调用回调,而只会更新值。
但我不知道如何将用户数据传递到 Python 中的 onChange 回调中。
我定义了我的回调函数:
def callback(value,cur_img):
cv2.GaussianBlur(cur_img, (5, 5), value)
Run Code Online (Sandbox Code Playgroud)
我得到了错误:
callback() takes exactly 2 arguments (1 given)
Run Code Online (Sandbox Code Playgroud)
因为它只将 bar 值参数传递到回调中。
但我真的需要 cv2.GaussianBlur 函数的 cur_img 。如何将 cur_img 参数传递到回调中?
我遵循https://spark.apache.org/docs/2.1.0/quick-start.html上的Scala教程
我的scala文件
/* SimpleApp.scala */
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
object SimpleApp {
def main(args: Array[String]) {
val logFile = "/data/README.md" // Should be some file on your system
val conf = new SparkConf().setAppName("Simple Application")
val sc = new SparkContext(conf)
val logData = sc.textFile(logFile, 2).cache()
val numAs = logData.filter(line => line.contains("a")).count()
val numBs = logData.filter(line => line.contains("b")).count()
println(s"Lines with a: $numAs, Lines with b: $numBs")
sc.stop()
}
}
Run Code Online (Sandbox Code Playgroud)
和build.sbt
name := "Simple Project"
version := "1.0"
scalaVersion …Run Code Online (Sandbox Code Playgroud) 我有日期字符串(例如:3/24/2020),我想将其转换为datetime64[ns]格式
df2['date'] = pd.to_datetime(df1["str_date"], format='%m/%d/%Y')
Run Code Online (Sandbox Code Playgroud)
在 vaex dataframe 上使用 pandasto_datetime会导致错误:
ValueError: time data 'str_date' does not match format '%m/%d/%Y' (match)
Run Code Online (Sandbox Code Playgroud)
我看到可能有重复的问题。
df2['pdate']=df2.date.astype('datetime64[ns]')
Run Code Online (Sandbox Code Playgroud)
然而,答案是类型转换。我的情况需要将格式('%m/%d/%Y')解析字符串为datetime64[ns],而不仅仅是类型转换。
解决方案:自定义函数,然后.apply