小编Hah*_*pro的帖子

Pytorch重塑张量维度

例如,我有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)

python numpy deep-learning pytorch tensor

27
推荐指数
7
解决办法
7万
查看次数

如何使用react-native-fbsdk的图形API?

我在githubFacebook开发者文档上阅读了该文档.
只有样品,仅此而已.没有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)

facebook-graph-api react-native

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

如何在Zeppelin中查看Spark和Scala的版本?

当我运行交互式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本地主机)

scala version apache-spark apache-zeppelin

10
推荐指数
1
解决办法
8932
查看次数

Windows 10上的领域数据浏览器

我设法使用这些代码获取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)

realm

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

Plotly:如何在带注释的热图中舍入显示文本,但在悬停时保持完整格式?

我正在绘制泰坦尼克号数据集的相关矩阵。

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)

not_round

我想四舍五入浮点数,因此它们在.点后显示较少的数字。

当前的解决方法实际上是在输入之前围绕 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)

圆形的

但是当我将鼠标悬停在上面时,解决方法也会使文本四舍五入。我想要完整详细的悬停文本,而显示文本是圆形的。

我可以在不更改输入数据框的情况下在每个单元格上显示更少的数字吗?

python plotly plotly-python

7
推荐指数
1
解决办法
716
查看次数

如何在ggplot2图的末尾删除间隙

我的输入文件在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

r ggplot2

6
推荐指数
1
解决办法
1776
查看次数

Unity的iOS版本需要In-App购买,尽管我的游戏不使用IAP

我在Unity中有一个使用Unity Analytics服务的游戏.我确保我的Unity版本在Unity编辑器中没有应用程序内购买.我从来没有在我的游戏中实现应用程序内购买,我已将IAP选项设置为关闭:

Unity_IAP_off

但Unity生成的我的Xcode项目显示错误,"'应用程序内购买'功能仅适用于在Apple Developer Program中注册的用户."
Xcode需要IAP

我错过了什么?

xcode unity-game-engine in-app-purchase ios

6
推荐指数
1
解决办法
818
查看次数

cv2.createTrackbar 将 userdata 参数传递给回调

我阅读了关于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 参数传递到回调中?

python opencv callback python-2.7

6
推荐指数
1
解决办法
2179
查看次数

提交火花时ClassNotFoundException scala.runtime.LambdaDeserialize

我遵循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)

scala sbt apache-spark spark-submit

5
推荐指数
1
解决办法
3369
查看次数

将字符串解析为 datetime64 的 Vaex 函数是什么,相当于 pandas to_datetime,允许自定义格式?

我有日期字符串(例如: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

python datetime datetime-format pandas vaex

5
推荐指数
1
解决办法
1965
查看次数