小编Adn*_*nan的帖子

Django Rest Framework:在执行创建re时在post数据中不需要序列化器字段

我有以下设置:

模型.py

class QuoteModel(models.Model):
    """
        this model stores initial information for the Quote
    """
    quote_number = models.CharField(max_length=20,
                                    unique=True,
                                    help_text="Please use the quote number from pms",)
    description = models.CharField(max_length=200,
                                   help_text="Enter description that you might find helpful")
    creator = models.ForeignKey(User)
    date_created = models.DateField(auto_now_add=True)
Run Code Online (Sandbox Code Playgroud)

序列化器.py

# Serializers define the API representation.
class QuoteModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = Quote
        fields = ('id', 'quote_number', 'description', 'creator', 'date_created')
        read_only_fields = ('date_created',)
Run Code Online (Sandbox Code Playgroud)

查看.py

class QuoteListCreateView(generics.ListCreateAPIView):
    queryset = Quote.objects.all()
    serializer_class = QuoteModelSerializer
    permission_classes = (permissions.IsAuthenticated, )

    def perform_create(self, …
Run Code Online (Sandbox Code Playgroud)

django-rest-framework

4
推荐指数
1
解决办法
3914
查看次数

theano函数的错误输入参数

我是theano的新手.我试图实现简单的线性回归,但我的程序抛出以下错误:

TypeError :('ofano函数的错误输入参数,名称为"/home/akhan/Theano-Project/uog/theano_application/linear_regression.py:36",索引0(从0开始)','预期类似于数组的对象,但是找到了一个变量:也许你试图在(可能是共享的)变量而不是数值数组上调用函数?')

这是我的代码:

import theano
from theano import tensor as T
import numpy as np
import matplotlib.pyplot as plt

x_points=np.zeros((9,3),float)
x_points[:,0] = 1
x_points[:,1] = np.arange(1,10,1)
x_points[:,2] = np.arange(1,10,1) 
y_points = np.arange(3,30,3) + 1


X = T.vector('X')
Y = T.scalar('Y')

W = theano.shared(
            value=np.zeros(
                (3,1),
                dtype=theano.config.floatX
            ),
            name='W',
            borrow=True
        )

out = T.dot(X, W)
predict = theano.function(inputs=[X], outputs=out)

y = predict(X)  # y = T.dot(X, W) work fine

cost = T.mean(T.sqr(y-Y))

gradient=T.grad(cost=cost,wrt=W)

updates = [[W,W-gradient*0.01]]

train = theano.function(inputs=[X,Y], outputs=cost, …
Run Code Online (Sandbox Code Playgroud)

theano

3
推荐指数
1
解决办法
2763
查看次数

标签 统计

django-rest-framework ×1

theano ×1