>>> X = np.array([[0,1],[2,3],[4,5],[6,7],[8,9],[10,11],[12,13],[14,15],[16,17],[18,19]])
>>>> X[:,0]
array([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18])
>>> X[:,1]
array([ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19])
>>> import torch.nn.functional as F
>>> F.softplus(X[:,0])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: softplus(): argument 'input' (position 1) must be Tensor, not numpy.ndarray
softplus针对的是tensor,如果是list,array都会报错
>>> import tensorflow as tf
>>> tf.constant([1,2,3,4,5,6],shape=[2,3])
2020-08-06 22:56:58.331010: I tensorflow/core/platform/cpu_feature_guard.cc:145] This TensorFlow binary is optimized with Intel(R) MKL-DNN to use the following CPU instructions in performance critical operations: SSE4.1 SSE4.2 AVX AVX2 FMA
To enable them in non-MKL-DNN operations, rebuild TensorFlow with the appropriate compiler flags.
2020-08-06 22:56:58.331941: I tensorflow/core/common_runtime/process_util.cc:115] Creating new thread pool with default inter op setting: 8. Tune using inter_op_parallelism_threads for best performance.
<tf.Tensor: id=2, shape=(2, 3), dtype=int32, numpy=
array([[1, 2, 3],
[4, 5, 6]], dtype=int32)>
>>> X=tf.constant([1,2,3,4,5,6],shape=[2,3])
>>> F.softplus(X[:,0])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: softplus(): argument 'input' (position 1) must be Tensor, not tensorflow.python.framework.ops.EagerTensor
这种定义tensor也会出错。
以下是正确使用:
>>> X = torch.Tensor([[1,2,3],[4,5,6]])
>>> F.softplus(X[:,0])
tensor([1.3133, 4.0181])