LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-30-2023, 10:26 PM   #1
centguy
Member
 
Registered: Feb 2008
Posts: 635
Blog Entries: 1

Rep: Reputation: 48
how to explain this inhomogeneous numpy.ndarray?


Why do I see a inhomogeneous numpy ndarray?

This is the output of a test script.

Quote:
type(train_data)
<class 'numpy.ndarray'>
train_data.shape
(25000,)
train_data[0]
[1, 14, 22, 16, 43, 2, 2, 2, 2, 65, 2, 2, 66, 2, 4, 2, 36, 2, 5, 25, 2, 43, 2, 2, 50, 2, 2, 9, 35, 2, 2, 5, 2, 4, 2, 2, 2, 2, 2, 2, 39, 4, 2, 2, 2, 17, 2, 38, 13, 2, 4, 2, 50, 16, 6, 2, 2, 19, 14, 22, 4, 2, 2, 2, 4, 22, 71, 87, 12, 16, 43, 2, 38, 76, 15, 13, 2, 4, 22, 17, 2, 17, 12, 16, 2, 18, 2, 5, 62, 2, 12, 8, 2, 8, 2, 5, 4, 2, 2, 16, 2, 66, 2, 33, 4, 2, 12, 16, 38, 2, 5, 25, 2, 51, 36, 2, 48, 25, 2, 33, 6, 22, 12, 2, 28, 77, 52, 5, 14, 2, 16, 82, 2, 8, 4, 2, 2, 2, 15, 2, 4, 2, 7, 2, 5, 2, 36, 71, 43, 2, 2, 26, 2, 2, 46, 7, 4, 2, 2, 13, 2, 88, 4, 2, 15, 2, 98, 32, 2, 56, 26, 2, 6, 2, 2, 18, 4, 2, 22, 21, 2, 2, 26, 2, 5, 2, 30, 2, 18, 51, 36, 28, 2, 92, 25, 2, 4, 2, 65, 16, 38, 2, 88, 12, 16, 2, 5, 16, 2, 2, 2, 32, 15, 16, 2, 19, 2, 32]
len(train_data[0])
218
train_data[1]
[1, 2, 2, 2, 2, 78, 2, 5, 6, 2, 2, 2, 2, 26, 4, 2, 8, 2, 2, 14, 2, 20, 13, 2, 2, 2, 2, 5, 2, 2, 2, 21, 14, 69, 2, 8, 30, 23, 7, 4, 2, 2, 93, 4, 2, 9, 2, 2, 5, 2, 4, 2, 9, 35, 2, 4, 2, 9, 2, 2, 4, 2, 9, 4, 2, 2, 19, 4, 2, 5, 89, 29, 2, 46, 37, 4, 2, 9, 45, 43, 38, 2, 2, 2, 4, 2, 26, 2, 5, 2, 11, 2, 2, 4, 2, 9, 2, 2, 7, 2, 2, 2, 2, 2, 2, 2, 2, 15, 2, 2, 68, 2, 2, 15, 2, 2, 2, 98, 5, 4, 2, 9, 43, 2, 2, 15, 2, 2, 5, 2, 2, 11, 2, 2, 2, 50, 9, 2, 2, 2, 5, 2, 2, 2, 2, 5, 4, 2, 2, 2, 2, 18, 2, 32, 2, 2, 14, 9, 6, 2, 78, 22, 2, 64, 2, 9, 8, 2, 2, 23, 4, 2, 15, 16, 4, 2, 5, 28, 6, 52, 2, 2, 33, 89, 78, 2, 16, 2, 95]
len(train_data[1])
189
 
Old 10-31-2023, 12:36 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,880
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
Meta: 'code' tag might be better than 'quote'
On: If you have a problem with your script, you might want to show us it.
 
Old 10-31-2023, 12:39 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,030

Rep: Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344
Good question! And how do you think we can give you any answer? Because you generated that ndarray. Most probably your python script has an error in line 42.
 
Old 11-01-2023, 12:06 AM   #4
centguy
Member
 
Registered: Feb 2008
Posts: 635

Original Poster
Blog Entries: 1

Rep: Reputation: 48
Code:
from tensorflow.keras.datasets import imdb
(trd, trl),(ted,tel)=imdb.load_data(num_words=100)
print("type(trd)")
print(type(trd))
print("trd.shape")
print(trd.shape)
print("trl.shape")
print(trl.shape)
print("ted.shape")
print(ted.shape)
print("tel.shape")
print(tel.shape)
print("trd[0]")
print(trd[0])
print("len(trd[0])")
print(len(trd[0]))
print("trd[1]")
print(trd[1])
print("len(trd[1])")
print(len(trd[1]))
 
Old 11-01-2023, 03:20 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,030

Rep: Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344Reputation: 7344
still the same. How do you think we know what was loaded and why is it inhomogeneous?
 
Old 11-01-2023, 04:01 AM   #6
centguy
Member
 
Registered: Feb 2008
Posts: 635

Original Poster
Blog Entries: 1

Rep: Reputation: 48
I found something useful here.

A=np.array([[1,2],[],[1,2,3,4]], dtype=object)

I got it from

Thank you for your attention! Cheers!
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Installing Python package including numpy , scipy,mpi4py , pycxx , symeig madani Linux - Software 1 03-14-2009 06:22 PM
python error , import numpy ufmale Programming 2 08-25-2008 11:59 PM
Scipy And Numpy automata Linux - Software 1 10-18-2007 06:50 AM
Numpy installation help wuzzo87 Linux - Software 2 04-06-2007 06:50 AM
Visual Python/Numpy uranologist Linux - Software 0 09-28-2003 10:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration