首页 > 编程知识 正文

tensor转array,numpy.ndarray是什么

时间:2023-05-03 11:32:57 阅读:144605 作者:2243

convertingbetweenatensorflowtf.tensorsandanumpyndarrayiseasy :

1.tensorflowoperationsautomaticallyconvertnumpyndarraystotensors。

2,numpyoperationsautomaticallyconverttensorstonumpyndarrays。

tensorsareexplicitlyconvertedtonumpyndarraysusingtheir.numpy (method.theseconversionsaretypicallycheapsincethearrrayandtf representation, if possible.howord sharingtheunderlyingrepresentationisn’talwayspossiblesincethetf.tensormaybehostedingpumemorywhilenumpyationumpyatation ry,andtheconversioninvolvesacopyfromgputohostmemory。

import numpy as np

nd array=NP.ones ([ 3,3 ] ) ) ) ) )。

打印(tensorflowoperationsconvertnumpyarraystotensorsautomatically ) )。

是打印(tensor )

打印(andnumpyoperationsconverttensorstonumpyarraysautomatically ) )

打印(NP.add (tensor,1 ) )

print('the.numpy ) ) methodexplicitlyconvertsatensortoanumpyarray ) ) )。

打印(tensor.numpy ) )

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。