当使用dplyr的"group_by"和"mutate"时,如果我理解正确,则根据group_by参数将数据帧拆分为不同的子数据帧.例如,使用以下代码:
 set.seed(7)
 df <- data.frame(x=runif(10),let=rep(letters[1:5],each=2))
 df %>% group_by(let) %>% mutate(mean.by.letter = mean(x))
Run Code Online (Sandbox Code Playgroud)
mean()连续应用于5个sub-dfs的列x,对应于a&e之间的字母.
所以你可以操纵sub-dfs的列,但是你可以自己访问sub-dfs吗?令我惊讶的是,如果我尝试:
 set.seed(7)
 data <- data.frame(x=runif(10),let=rep(letters[1:5],each=2))
 data %>% group_by(let) %>% mutate(mean.by.letter = mean(.$x))
Run Code Online (Sandbox Code Playgroud)
结果是不同的.从这个结果,可以推断出"." df并不代表sub-dfs而只代表"data"一个(group_by函数不会改变任何东西).
原因是我想使用一个stat函数,它将数据帧作为每个sub-dfs的参数.谢谢 !
如何排除打包文件夹conda build?
我正在使用构建第一个软件包conda build。
我的meta.yaml文件如下所示:
package:
    name: 'some_name'
    version: {{ load_setup_py_data().get('version') }}
source:
    path: ./
build:
    script: python setup.py install --single-version-externally-managed --record=record.txt
requirements:
    run:
        - python >=3.6
        - pandas >=0.2
        - numpy >=1.12
        # Packages that must be installed
        # in the user's conda environment
        # to run this package.
    build:
        # Packages used by setup.py
        # to install this package.
        # May also install compilers
        # for non-python code.
        - python
        - …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Pytorch的函数torch.conv2d但无法得到我理解的结果......
这是一个简单的示例,其中内核 ( filt) 与输入 ( im) 的大小相同,以解释我正在寻找的内容。
import pytorch
filt = torch.rand(3, 3)
im = torch.rand(3, 3)
Run Code Online (Sandbox Code Playgroud)
我想计算一个没有 padding 的简单卷积,所以结果应该是一个标量(即 1x1 张量)。
我试过这个conv2d:
# I have to convert image and kernel to 4 dimensions tensors to use conv2d
im_torch = im.reshape((im_height, filt_height, 1, 1))
filt_torch = filt.reshape((filt_height, im_height, 1, 1))
out = torch.nn.functional.conv2d(im_torch, filt_torch, stride=1, padding=0)
print(out)
Run Code Online (Sandbox Code Playgroud)
但结果并不是我所期望的:
tensor([[[[0.6067]], [[0.3564]], [[0.5397]]],
    [[[0.2557]], [[0.0493]], [[0.2562]]],
    [[[0.6067]], [[0.3564]], [[0.5397]]]])
Run Code Online (Sandbox Code Playgroud)
为了了解我想要什么,我想重现 scipyconvolve2d …
如何实现这两个Keras模型(受到 Datacamp 课程“Python 中 Keras 的高级深度学习”的启发)Pytorch:
具有 1 个输入、2 个输出的分类:
from keras.layers import Input, Concatenate, Dense
from keras.models import Model
input_tensor = Input(shape=(1,))
output_tensor = Dense(2)(input_tensor)
model = Model(input_tensor, output_tensor)
model.compile(optimizer='adam', loss='categorical_crossentropy')
X = ... # e.g. a pandas series
y = ... # e.g. a pandas df with 2 columns
model.fit(X, y, epochs=100)
Run Code Online (Sandbox Code Playgroud)
具有分类和回归的模型:
from keras.layers import Input, Dense
from keras.models import Model
input_tensor = Input(shape=(1,))
output_tensor_reg = Dense(1)(input_tensor)
output_tensor_class = Dense(1, activation='sigmoid')(output_tensor_reg) …Run Code Online (Sandbox Code Playgroud) 我正在阅读Graham Hutton的"伟大"书的第2版"Haskell的Progamming"(剑桥出版社).
阅读State Monad部分,我偶然发现了一个我给自己做的小任务.
你怎么能用where而不是重写以下内容let?
type State = Int
newtype ST a = S (State -> (a, State))
instance Functor ST where
    -- fmap :: (a -> b) -> ST a  -> ST b
    fmap g st = S (\state -> let (x, s') = app st state in (g x, s'))
Run Code Online (Sandbox Code Playgroud)
我试过这个代码的变体,但它不起作用:
instance Functor ST where
   -- fmap :: (a -> b) -> ST a  -> ST b
   fmap g st …Run Code Online (Sandbox Code Playgroud) 很抱歉这个问题,但我刚开始研究Haskell ...我的问题与"定点组合"有关...
根据此维基百科页面部分功能fix,使得
fix f = f (fix f)
Run Code Online (Sandbox Code Playgroud)
是类型(或至少可以是类型)
(a -> a) -> a
Run Code Online (Sandbox Code Playgroud)
有人能解释一下为什么吗?
谢谢 !
您是否还有任何指针(网页,书籍......)解释如何根据其定义猜测函数的类型?