有很多关于如何创建和使用 TensorFlow 数据集的示例,例如
dataset = tf.data.Dataset.from_tensor_slices((images, labels))
Run Code Online (Sandbox Code Playgroud)
我的问题是如何以 numpy 形式从 TF 数据集中取回数据/标签?换句话说,想要是上面那一行的反向操作,即我有一个 TF 数据集,想从中取回图像和标签。
我试图了解如何在aioweb框架内从coroutine处理程序运行异步进程.这是一个代码示例:
def process(request):
# this function can do some calc based on given request
# e.g. fetch/process some data and store it in DB
# but http handler don't need to wait for its completion
async def handle(request):
# process request
process(request) ### THIS SHOULD RUN ASYNCHRONOUSLY
# create response
response_data = {'status': 'ok'}
# Build JSON response
body = json.dumps(response_data).encode('utf-8')
return web.Response(body=body, content_type="application/json")
def main():
loop = asyncio.get_event_loop()
app = web.Application(loop=loop)
app.router.add_route('GET', '/', handle)
server = loop.create_server(app.make_handler(), '127.0.0.1', 8000) …Run Code Online (Sandbox Code Playgroud) 我试图找出一种方法,我可以在pandas数据框中选择行,因为某些值将在我的列表中.例如
df = pd.DataFrame(np.arange(6).reshape(3,2), columns=['A','B'])
A B
0 0 1
1 2 3
2 4 5
Run Code Online (Sandbox Code Playgroud)
我知道我可以选择某一行,例如
df[df.A==0]
Run Code Online (Sandbox Code Playgroud)
将选择A = 0的行.我想要的是选择多个行,其值将在我的列表中,例如[0,2]中的A. 我试过了
df[df.A in [0,2]]
df[list(df.A)==[0,2]]
Run Code Online (Sandbox Code Playgroud)
但没有任何作用.在R语言中,我可以提供%in%运算符.在python语法中我们可以在[0,2]中使用A等.在这种情况下,如何在pandas中选择行的子集?谢谢,瓦伦丁.
I'm trying to understand how to get client's certificates in Go web server. Here is a server code:
package main
import (
"log"
"net/http"
"net/http/httputil"
)
func defaultHandler(w http.ResponseWriter, r *http.Request) {
dump, err := httputil.DumpRequest(r, true)
log.Println("HTTP request", r, string(dump), err)
log.Println("HTTP TLS", r.TLS, string(r.TLS.TLSUnique))
certs := r.TLS.PeerCertificates
log.Println("HTTP CERTS", certs)
w.WriteHeader(http.StatusMethodNotAllowed)
w.Write([]byte("Hello"))
}
func main() {
http.HandleFunc("/", defaultHandler)
http.ListenAndServeTLS(":8080", "server.crt", "server.key", nil)
}
Run Code Online (Sandbox Code Playgroud)
and here is client code
package main
import (
"crypto/tls"
"io/ioutil"
"log"
"net/http"
"os"
) …Run Code Online (Sandbox Code Playgroud) 我试图用Go语言来理解时间转换的问题.这是代码示例:
package main
import (
"fmt"
"time"
)
func unix2Str(ts int64) string {
const layout = "20060102"
t := time.Unix(ts, 0)
return t.Format(layout)
}
func unixTime(ts string) int64 {
const layout = "20060102"
t, err := time.Parse(layout, ts)
if err != nil {
fmt.Println(err)
return 0
}
return t.Unix()
}
func main() {
ts1 := "20110320"
ts2 := "20110321"
ut1 := unixTime(ts1)
ut2 := unixTime(ts2)
fmt.Println(ts1, ut1, unix2Str(ut1))
fmt.Println(ts2, ut2, unix2Str(ut2))
}
Run Code Online (Sandbox Code Playgroud)
它打印以下输出:
20110320 1300579200 20110319
20110321 1300665600 20110320
Run Code Online (Sandbox Code Playgroud)
但是,由于我从字符串格式转换为Unix并且反向,我希望字符串格式的日期具有相同的结果.但事实并非如此.实际上,打印的unix时间 …
根据 Prometheus-operator文档,我们应该能够通过秘密文件轻松提供我们的附加配置。这一步真的有人成功吗?我有几个问题:
file_sd_configs:吗?如果可以,如何将这些文件提供到 prometheus 清单文件中?不管这些问题,我都很难添加额外的配置。我基本上遵循了文档中的确切步骤 ,这是我的观察:
cat prometheus-additional.yaml
- job_name: "prometheus-custom"
static_configs:
- targets: ["localhost:9090"]
Run Code Online (Sandbox Code Playgroud)
kubectl create secret generic additional-scrape-configs --from-file=prometheus-additional.yaml
Run Code Online (Sandbox Code Playgroud)
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
name: prometheus
spec:
replicas: 2
resources:
requests:
memory: 400Mi
additionalScrapeConfigs:
name: additional-scrape-configs
key: prometheus-additional.yaml
Run Code Online (Sandbox Code Playgroud)
kubectl apply -f prometheus.yaml
Run Code Online (Sandbox Code Playgroud)
kubectl logs prometheus-prometheus-0 -c prometheus
level=info ts=2019-12-05T18:07:30.217852541Z caller=main.go:302 msg="Starting Prometheus" version=" (version=2.7.1, branch=HEAD, …Run Code Online (Sandbox Code Playgroud) 我试图了解如何读取文件的内容,计算其散列并一次性返回其字节。到目前为止,我分两步完成,例如
// calculate file checksum
hasher := sha256.New()
f, err := os.Open(fname)
if err != nil {
msg := fmt.Sprintf("Unable to open file %s, %v", fname, err)
panic(msg)
}
defer f.Close()
b, err := io.Copy(hasher, f)
if err != nil {
panic(err)
}
cksum := hex.EncodeToString(hasher.Sum(nil))
// read again (!!!) to get data as bytes array
data, err := ioutil.ReadFile(fname)
Run Code Online (Sandbox Code Playgroud)
显然,这不是最有效的方法,因为读取发生两次,一次在复制中传递给散列器,另一个在 ioutil 中读取文件并返回字节列表。我正在努力理解如何将这些步骤组合在一起并一次性完成,读取数据一次,计算任何散列并将其与字节列表一起返回到另一层。
我正在配对 TFRecords,它为我提供了一个标签作为数值。但在读取原始记录时,我需要将该值转换为分类向量。我怎样才能做到这一点。以下是读取原始记录的代码片段:
def parse(example_proto):
features={'label':: tf.FixedLenFeature([], tf.int64), ...}
parsed_features = tf.parse_single_example(example_proto, features)
label = tf.cast(parsed_features['label'], tf.int32)
# at this point label is a Tensor which holds numerical value
# but I need to return a Tensor which holds categorical vector
# for instance, if my label is 1 and I have two classes
# I need to return a vector [1,0] which represents categorical values
Run Code Online (Sandbox Code Playgroud)
我知道有tf.keras.utils.to_categorical函数,但它不接受张量作为输入。
将go mod tidy包依赖项添加到 go.mod 文件中。我们如何在不手动编辑 go.mod 文件的情况下自动更新它们,例如删除一些条目?例如,如果我使用 make,我想添加一个类似的命令,该命令可以更新我的包/存储库的所有依赖项,然后使用最新版本的包依赖项编译代码。
go ×4
python ×3
tensorflow ×2
aiohttp ×1
asynchronous ×1
client ×1
dependencies ×1
file ×1
hash ×1
https ×1
pandas ×1
prometheus ×1
server ×1
ssl ×1
time ×1