टेंसर के मानक विचलन की गणना करने के लिए बस टेंसरफ्लो में np.std() के बराबर की तलाश है।tensorFlow में np.std() के बराबर क्या है?
14
A
उत्तर
22
माध्य और भिन्नता प्राप्त करने के लिए बस tf.nn.moments
का उपयोग करें।
mean, var = tf.nn.moments(x, axes=[1])
के लिए अधिक पर tf.nn.moments
पैरामीटर देखने docs
3
आप निम्न कोड Keras से अनुकूलित में reduce_std
उपयोग कर सकते हैं:
#coding=utf-8
import numpy as np
import tensorflow as tf
def reduce_var(x, axis=None, keepdims=False):
"""Variance of a tensor, alongside the specified axis.
# Arguments
x: A tensor or variable.
axis: An integer, the axis to compute the variance.
keepdims: A boolean, whether to keep the dimensions or not.
If `keepdims` is `False`, the rank of the tensor is reduced
by 1. If `keepdims` is `True`,
the reduced dimension is retained with length 1.
# Returns
A tensor with the variance of elements of `x`.
"""
m = tf.reduce_mean(x, axis=axis, keep_dims=True)
devs_squared = tf.square(x - m)
return tf.reduce_mean(devs_squared, axis=axis, keep_dims=keepdims)
def reduce_std(x, axis=None, keepdims=False):
"""Standard deviation of a tensor, alongside the specified axis.
# Arguments
x: A tensor or variable.
axis: An integer, the axis to compute the standard deviation.
keepdims: A boolean, whether to keep the dimensions or not.
If `keepdims` is `False`, the rank of the tensor is reduced
by 1. If `keepdims` is `True`,
the reduced dimension is retained with length 1.
# Returns
A tensor with the standard deviation of elements of `x`.
"""
return tf.sqrt(reduce_var(x, axis=axis, keepdims=keepdims))
if __name__ == '__main__':
x_np = np.arange(10).reshape(2, 5).astype(np.float32)
x_tf = tf.constant(x_np)
with tf.Session() as sess:
print(sess.run(reduce_std(x_tf, keepdims=True)))
print(sess.run(reduce_std(x_tf, axis=0, keepdims=True)))
print(sess.run(reduce_std(x_tf, axis=1, keepdims=True)))
print(np.std(x_np, keepdims=True))
print(np.std(x_np, axis=0, keepdims=True))
print(np.std(x_np, axis=1, keepdims=True))
+0
मैं tf1.4 का उपयोग कर रहा हूं, tf.nn.moments मुझे किसी कारण से सही परिणाम नहीं देता है ... मैंने आपके संस्करण की कोशिश की और यह पहली कोशिश पर काम किया :) +1 –
संबंधित मुद्दे
- 1. tensorflow में `*` दस्तावेज कहां है?
- 2. क्या Python में बराबर बराबर है?
- 3. Tensorflow में global_step का क्या अर्थ है?
- 4. TensorFlow में tf.app.flags का उद्देश्य क्या है?
- 5. tensorflow में numpy.newaxis का विकल्प क्या है?
- 6. क्या सी ++ में जावा बराबर विधि के बराबर है?
- 7. java.util.Arrays में बराबर() के रनटाइम क्या है?
- 8. क्या शक्तियों में "... || मरने" के बराबर है?
- 9. स्विफ्ट में @autoreleasepool के बराबर क्या है?
- 10. CoreFoundation में NSHomeDirectory() के बराबर क्या है?
- 11. mysql में REGEXP_SUBSTR के बराबर क्या है?
- 12. क्या एक्सएमएल में setColorFilter() के बराबर है?
- 13. आईओएस में एपीके के बराबर क्या है?
- 14. क्या सी # में ग्रोवी के बराबर है?
- 15. MySQL में 'go' के बराबर क्या है?
- 16. क्या शक्तियों में "यह" के बराबर है?
- 17. .NET में जेपीए के बराबर क्या है?
- 18. WinRT में SecureString के बराबर क्या है?
- 19. सी ++ में Thread.SetApartmentState के बराबर क्या है?
- 20. एक्सेल वीबीए में "! =" के बराबर क्या है?
- 21. पायथन में 'मणि' के बराबर क्या है?
- 22. जावास्क्रिप्ट में .get के बराबर क्या है?
- 23. विजुअल बेसिक में = = के बराबर क्या है?
- 24. क्या .NET में JMS के बराबर है?
- 25. Angular2 में ngSrc के बराबर क्या है?
- 26. क्या स्कैला में SuppressWarnings के बराबर है?
- 27. tensorflow
- 28. tensorflow आलसी है?
- 29. tensorflow में sampled_softmax_loss और nce_loss के बीच क्या अंतर है?
- 30. tensorflow में गति के साथ एसजीडी
मैं इस C++ एपीआई कैसे प्राप्त कर सकते हैं? –
मुझे केवल सी ++ एपीआई में अर्थ के लिए प्रलेखन दिखाई देता है: https://www.tensorflow.org/api_docs/cc/class/tensorflow/ops/mean मुझे लगता है कि आपको स्वयं को भिन्नता की गणना करनी होगी। योग [(x- u)^2] आप पाइथन स्रोत कोड के माध्यम से खोदने में सक्षम हो सकते हैं कि वे बैक एंड को कैसे कॉल करते हैं यह देखने के लिए कि भिन्नता को और अधिक कुशलतापूर्वक गणना कैसे करें। – Steven