<jupyter_start><jupyter_text>SparseTensorExample* 듬성듬성한 데이터를 표현하는 방법* SparseTensor(indices=[[0, 0], [1, 2]], values=[1, 2], dense_shape=[3, 4])>[[1, 0, 0, 0]>[0, 0, 2, 0]>[0, 0, 0, 0]]<jupyter_code>import tensorflow as tf
import numpy as np



spase_data = ['Bachelors', 'Some-college', 'male','female']

# SparseTensor(indices=[[0, 0], [1, 2]], values=[1, 2], dense_shape=[3, 4])
#tf.SparseTensor(
#          indices=[[i, 0] for i in range(df[k].size)],
#          values=df[k].values,
#          dense_shape=[df[k].size, 1])

spase_tensor = tf.SparseTensor(indices = [[i,0] for i in range(len(spase_data))]
                               , values = spase_data
                               , dense_shape = [len(spase_data), 1])#표현 행렬

spase_tensor2 = tf.SparseTensor(indices=[[0, 0], [1, 2]], values=[1, 2], dense_shape=[3, 4])
dense = tf.sparse_tensor_to_dense(spase_tensor, default_value='')
dense2 = tf.sparse_tensor_to_dense(spase_tensor2)

sess = tf.InteractiveSession()
print(spase_tensor.eval())
print(spase_tensor2.eval())
print(dense.eval())
print(dense2.eval())
sess.close()<jupyter_output>SparseTensorValue(indices=array([[0, 0],
       [1, 0],
       [2, 0],
       [3, 0]]), values=array([b'Bachelors', b'Some-college', b'male', b'female'], dtype=object), dense_shape=array([4, 1]))
SparseTensorValue(indices=array([[0, 0],
       [1, 2]]), values=array([1, 2], dtype=int32), dense_shape=array([3, 4]))
[[b'Bachelors']
 [b'Some-college']
 [b'male']
 [b'female']]
[[1 0 0 0]
 [0 0 2 0]
 [0 0 0 0]]
{'fraction_non_alphanumeric': 0.20767195767195767, 'fraction_numerical': 0.05092592592592592, 'mean_word_length': 4.3087719298245615, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '275607', 'license': 'MIT', 'n_tokens_mistral': 677, 'n_tokens_neox': 630, 'n_words': 124, 'path': 'skp_edu_docker/code/WideAndDeep/sparseTensor_practice.ipynb', 'repo_name': 'TensorMSA/hoyai_docker', 'size': '1512'}