只需更新我的可可豆荚,即可更新火力库。这行代码是旧方法,现在是错误的:
import tensorflow as tf
def method(i):
# Placeholder logic
return tf.cast(tf.range(i, i + 100), tf.float32)
def condition(i, var):
return tf.less(i, 100)
def body(i, var):
# Produce new row
updated_row = method(i)
# Index vector that is 1 only on the row to update
idx = tf.equal(tf.range(tf.shape(a)[0]), i)
idx = tf.cast(idx[:, tf.newaxis], var.dtype)
# Compose the new tensor with the old one and the new row
var_updated = (1 - idx) * var + idx * updated_row
return [tf.add(i, 1), var_updated]
# Start with zeros
a = tf.zeros([100, 100], tf.float32)
i = tf.constant(0)
i_end, a_updated = tf.while_loop(condition, body, [i, a], parallel_iterations=10)
with tf.Session() as sess:
print(sess.run(a_updated))
下面的代码是现在提取URL字符串的正确方法。但是,我需要有关如何将该字符串放入数组以保存到Firebase的帮助。
[[ 0. 1. 2. ... 97. 98. 99.]
[ 1. 2. 3. ... 98. 99. 100.]
[ 2. 3. 4. ... 99. 100. 101.]
...
[ 97. 98. 99. ... 194. 195. 196.]
[ 98. 99. 100. ... 195. 196. 197.]
[ 99. 100. 101. ... 196. 197. 198.]]
我如何将“值”保存为孩子
let downloadURL = metaData!.downloadURL()!.absoluteString
let values: Dictionary<String, Any> = ["download_url": downloadURL]
使用下面的答案...
当我使用下面提交的答案时,我得到一个打印输出,说“用户无权访问gs://shoppeer-e7270.appspot.com/(null)”。我要完成的所有工作就是获取该URL字符串并将其添加到我的“值”(即字典)中。
我用于图像上传和保存为孩子的完整代码
storageRef.downloadURL(completion: {(url, error) in
if error != nil {
print(error!.localizedDescription)
return
}
let downloadURL = url?.absoluteString
})
let values: Dictionary<String, Any> = ["download_url": downloadURL]
此功能仅适用于下载URL字符串为空
let databaseRef = Database.database().reference()
let path = databaseRef.child("posts").child((self.loggedInUser?.uid)!).childByAutoId()
path.setValue(values) { (error, ref) -> Void in
if error != nil {
print("error saving post in db")
} else {
let storageRef = Storage.storage().reference().child("posts_requests").child((self.loggedInUser?.uid)!).child(snapshot.childSnapshot(forPath: "uid").value as! String).child(snapshot.childSnapshot(forPath: "uid").value as! String).child(snapshot.childSnapshot(forPath: "imageID").value as! String)
storageRef.delete(completion: { error in
if let error = error {
print(error)
} else {
print("Successful Delete")
}
})
}
}
答案 0 :(得分:1)
values
是Dictionary
,而不是Array
,但是如果要向其中添加downloadURL
,则需要在的完成处理程序中进行storageRef.downloadURL(completion:)
,因为这是异步方法。
storageRef.downloadURL(completion: {(url, error) in
if error != nil {
print(error!.localizedDescription)
return
}
let downloadURL = url?.absoluteString
let values: Dictionary<String, Any> = ["download_url": downloadURL]
})
答案 1 :(得分:1)
下载URL仅在完成处理程序内部可用。
storageRef.downloadURL(completion: {(url, error) in
if error != nil {
print(error!.localizedDescription)
return
}
let downloadURL = url?.absoluteString
let values: Dictionary<String, Any> = ["download_url": downloadURL]
let databaseRef = Database.database().reference()
let path = databaseRef.child("posts").child((self.loggedInUser?.uid)!).childByAutoId()
path.setValue(values) { (error, ref) -> Void in
...