Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
alternative scheme for loading binary data
numpy, scipy and matplotlib example from a Well House Consultants training course
More on numpy, scipy and matplotlib [link]

This example is described in the following article(s):
   • Arrays v Lists - what is the difference, why use one or the other - [link]

Source code: npx2 Module: Y118
import numpy as np
import os.path

# Could dimension array based on file size ...

fs = os.path.getsize("talker.gif")
print fs

fh = open("talker.gif")

lynes = []

while True:
        stuff = np.fromfile(fh,dtype=np.int16,count=16)
        if not stuff.any(): break

        # giving a list of arrays :-/ ...

        lynes.append(stuff)
        print stuff

"""

wizard:plymgen graham$ python npx2
2825
[18759 14406 24889 72 73 247 0 0 -1 4351 4112 3600
  3096 3084 2572 2068]
[2056 1544 3600 3596 -257 2815 3080 2572 3598 4108 4630 540 1536 1546 3602
 5642]
[ 3088 4632 6670 4116 2588 3592 2572 4112 5134 4114 -1258 -7
  -771 -769 -261 4116]
[ 6430 7703 -29552 -23141 -20319 1030 2060 3590 2058 3088
   4618 3086 4116 5646 4114 5144]
[ 6674 5142 7196 7963 7454 -2271 -523 -16448 -5181 -4374
    518 30484 32373 -5138 -3336 -1552]
[ -7195 1772 3588 2058 4370 7438 3086 4630 6672 4628
   5660 7700 6684 -31452 -26240 -28524]
[ 21923 23891 -11562 -23579 -20576 -14134 -8238 -6179 -3084 3832
   8458 4372 6433 9750 11826 12355]
[ 14638 18507 28504 -32661 23389 -17306 -13639 -15675 -15917 -12610
  -5910 1779 10240 1288 3097 7177]
[ 3345 2087 4614 3858 3105 5642 3086 4120 6670 4628 9246 12066
 19536 12902 15408 29045]
[ 8330 9503 -25698 -19537 -15440 31870 -1656 -264 1 1032
   4610 1289 1568 5124 3604 3639]
[ 9994 1544 3093 6410 5144 7471 13849 3086 15898 25144 8227 6709
  9752 7198 15146 18745]
[ 31358 11158 12586 -30069 -12142 -10545 -4369 -4619 -3092 2058
   5146 10769 15425 11109 16680 6426]
[ 23074 28759 26216 -24199 -18274 -14905 -10537 -8491 773 792
   3330 1286 2320 5128 4370 5661]
[ 8469 -29811 -21600 -19286 1 272 3328 1286 3602 7181
  16963 25423 28770 -26214 423 5376]
[ 0 10 1536 0 4 512 1028 1038 3076 1542 2062 4616 4626 2086 4104
 2570]
[2066 3592 3084 4116 6672 2570 3600 5646 4112 3096 4620 2056 4620 6674 3598
 5140]
[7188 2570 4110 5648 4626 3096 4108 3598 4114 5136 2056 5642 6934 4626 2582
 3082]
[ 5397 3097 3596 3598 4112 4624 4626 5396 5653 -2314 -3589 -2575
 -1286 20989 21073 -258]
[1279 2309 4624 3604 4368 2568 4106 4626 5138 3092 3086 5138 2578 2316 4624
 1550]
[ 520 2568 3076 2062 4624 2572 1292 4110 2057 522 3596 4102 2578 5138 5644
 3864]
[2568 2560 524 3596 3588 1552 4624 4616 2580 5652 6156 5145 3596 4098 1298
 5652]
[ 14858 12348 8737 -28645 -31087 2570 1280 261 2056 4098
   2064 3084 2054 1032 3598 2568]
[1546 4112 4618 3090 3084 3592 2574 4112 2060 1544 4626 5134 4116 2570 3080
 2572]
[3598 5644 4886 4112 4622 4114 4628 3088 2570 3086 6412 6425 5140 4628 4626
 3598]
[ 2574 2570 1285 517 514 -1 8703 1273 1 -256 11264 0
     0 72 73 2048]
[ 255 2051 18460 -24400 -31807 4872 23594 -20280 17313 2433
  -7118 -18998 -24085 -29755 -5354 -11912]
[-22575 2959 18759 -5028 4600 8868 -27706 30488 -1535 -6398
 -25651 23580 -18350 -16294 -10646 5310]
[ -1422 12800 -19831 -15833 11100 -23406 -6798 5674 31825 -6936
  29537 20263 15262 11609 14494 -7678]
[ 10931 8257 20526 -20396 10976 -30315 -20652 -17944 10147 27766
  32059 -20924 -32376 -7038 21910 19359]
[-31462 -20054 -32665 11029 1910 -9520 -26677 -32618 7256 6252
   9026 -12476 9889 12655 -11986 -14461]
[-24246 13365 21770 23705 -27485 -13339 17814 -18419 26673 -27443
 -28623 30930 -951 18352 8474 6227]
[ 4429 -30525 -26095 26839 -14326 11678 -31589 6955 3458 -14015
 -15084 7948 -23369 -19947 -11960 -26326]
[ 444 -27704 10019 -24543 -3143 -19226 -11258 -29120 -13673 18676
  22669 18180 -24168 -32751 -13736 10708]
[ 22527 -818 -3143 -7192 -9327 16840 -11451 -8169 2011 -28218
  16996 -17898 4452 4050 28456 94]
[ -2822 -24410 -14416 -31973 -3820 579 1521 -31552 14116 -16232
  15055 -5950 24503 -12161 30793 11457]
[ 22708 -26320 31768 -20380 11869 21572 -15775 -20438 25548 3403
 -24024 23704 -1239 -5964 -29854 -23373]
[ 23864 5746 -31808 11471 17447 -30624 7448 -30868 9416 31908
 -30046 -19926 17052 -29477 -27645 -16318]
[ 19602 10542 27915 22986 -12976 -3278 4816 1035 22615 785
  29801 -19480 10895 3253 -7111 11153]
[ -9930 -27676 9651 1383 -9683 29524 15566 -27471 18160 14849
   5668 14916 24800 3859 -19967 18824]
[ 29222 -26038 9449 -11116 -12279 13670 -4886 26387 25347 -3852
   5846 16384 -13197 -4292 14836 27878]
[ 1608 10282 -19814 26409 13672 -21298 20371 14381 8304 7748
  21528 -13435 -15319 -8184 139 2299]
[ 11007 -21269 12980 23712 13569 28888 8578 -5041 -10928 -502
   5948 -21205 4804 27499 -18318 -31122]
[ 3395 -11196 -27679 -20469 23304 -19220 7858 23691 5042 -32060
  10383 1136 -11311 -16111 14138 -19156]
[ 4836 -4768 -10240 -3102 12300 9363 2961 18762 -3084 -18078
 -21772 -7390 4748 -11292 13837 -18404]
[ 1185 15434 16384 -16145 -21941 10306 -19598 4900 10767 27758
  -4367 16709 -15892 -16117 6915 9884]
[ 8818 24738 7106 25722 769 15174 -8192 -15093 7925 16444
   6920 -3820 3718 31871 20844 31238]
[-20276 -14070 23269 -22052 17010 29108 2692 -23456 -11926 -30177
  16916 27906 -30284 13120 -12367 12909]
[ 4422 1071 672 3407 733 455 -17377 -3006 18028 15647
  29675 10397 23090 19714 -31693 3905]
[ 8318 -30815 8984 956 -10801 26034 -19027 -12640 21453 5058
 -21925 -19488 -29886 -24027 9335 -2910]
[-27649 14348 5996 -2336 19931 -22722 7817 25717 416 -30653
 -28116 6664 -31611 224 -8898 29584]
[ 3406 -29844 -12352 -25626 -1741 -18206 -18715 -32728 24894 -7836
  17185 9279 1362 1966 12876 2823]
[-25414 16562 8928 24600 443 30972 7422 -1083 12296 460
  16479 20621 28176 -3968 -20919 -3950]
[ 19376 22284 8800 -4859 -7241 -17490 -17293 -12549 9163 11784
 -14108 -19449 13280 3395 -12266 17393]
[-32485 28936 -3066 -6217 25790 -11025 -9197 12539 -29548 -28490
  21021 -12208 15439 -30667 1169 7709]
[ 4420 6341 4225 129 10247 2752 20292 1149 24416 10355
 -29898 -10151 4450 24704 9160 8192]
[ 13189 -15908 29823 -32376 2063 -30239 -32699 31264 15392 -20326
  12768 27022 25420 -31458 17032 -13799]
[ 768 6625 1924 -22381 5506 12448 3718 -24383 -31729 -31712
  19493 -15872 -30232 23632 -25564 13894]
[ 1279 2144 14387 3457 19367 11784 8202 392 -7976 25356 16984 28160
  1169 -5085 5345 -5973]
[ -4639 -10114 32156 -3836 -27260 -31920 -7654 -17008 19588 5296
 -26469 5249 28882 6280 24836 11790]
[-32440 2049 17824 29147 22033 -23487 15110 24752 12295 24960
 -18655 17088 26155 2817 -13307 2144]
[-28627 6082 -3824 30853 25536 -25570 25739 25831 -17963 13590
 -28087 -11358 135 20962 27150 -15536]
[ 18207 -14224 10273 65 14456 4233 -16273 9665 -12006 13
 -23652 796 -14365 31516 18807 -2529]
[ 7982 -26374 14791 20906 25101 24936 2929 16721 26150 -29136
 -23439 7683 -20472 5378 -32448 522]
[ 936 -9446 18024 26412 -32727 28250 -26895 -9031 13669 16870
  15109 17456 -30201 -31400 19506 3640]
[ -8190 608 -20305 14725 29086 27149 25432 2458 9900 25747
  19833 -8191 -26798 11452 9414 -23042]
[-28417 -8169 1665 8348 12998 -20070 31500 8212 -25580 1544
 -27135 -29375 -30612 -25085 -25420 11687]
[-22035 30095 -11540 537 -15344 5665 962 -9147 160 -18396
  29828 13414 -13283 -29259 1136 -22624]
[ 5357 3704 26733 7523 -26452 8258 -20230 18704 28540 29242
 -29480 -27635 21091 -24127 -23212 30726]
[ 13009 -17828 270 16524 28684 8560 -12223 -32683 24601 5889
  -1953 23744 -11374 -15917 3357 19880]
[-14510 -12743 3761 -16047 5346 18906 8328 12578 18816 184
 -29424 248 -23406 -19069 -10593 145]
[-26381 135 20950 29071 -16384 2587 -12903 -29684 2560 -29602
  17716 -29883 9381 1849 18626 18]
[-17121 1408 -6084 -29535 28771 -26621 -24313 3213 4198 -18760
   3026 30120 9116 25747 -31871 -30638]
[ 5218 -20310 14336 -28300 -31932 -27052 -11402 -4916 -26858 3844
  11350 2763 2100 9283 -20262 -31579]
[-25345 29494 21929 26285 -2921 24075 -16180 32016 -15920 23566
  -9370 4827 -21811 -15661 -4628 12634]
[ 22154 12760 -19803 17808 27692 -31168 1070 -22208 12549 21358
 -16369 989 -26776 13110 -20760 3960]
[-15104 28711 8098 26863 10183 4266 21382 8832 -3567 -30621
 -15498 -8741 -5393 -17291 -31267 6626]
[ 24590 29952 22196 22545 -15472 -30172 -21280 -13178 -17321 -27146
  32013 31729 10118 24604 -7148 -14544]
[ 9277 2257 -20388 960 29918 -32312 -25621 1504 -18545 8322
   1384 -1479 -29887 -2000 8970 18483]
[-30095 -21717 -13726 6262 -9025 16645 -9869 3649 31862 4448
 -14890 30856 -25507 -7328 22650 8124]
[ 18276 -15816 -29631 16411 -24702 -9961 -28815 -29641 4191 9104
 -12004 1672 -10693 6280 30493 -14441]
[ 26187 -29647 -12273 10378 -31929 -19943 -31608 21534 4720 26405
 -19207 3614 3247 -12258 26122 17220]
[ 6886 -28449 9349 22728 11238 26323 -8501 12221 -20601 13718
 -12925 13792 14415 15299 -11782 25356]
[-31760 -29172 13226 -20105 26508 8944 -18664 12292 5528 8400
  16518 16944 -5098 1896 50 1152]
[ 13036 -13116 27058 -24908 -29767 18650 6023 -32751 888 3584
 -30144 31761 1824 -5960 -22519 8203]
[ 1386 -26049 1487 16659 4120 -32751 8229 4641 30866 4418
  10274 7659 6315 11727 28446 23435]
[-32228 30082 4290 -30575 12000 4284 8199 -13448 30759 -18738
 -14410 -32437 -23166 4497 2388 -18738]
[-25145 28397 -17849 -32000 -15216 2083 -14766 -27806 -8709 13794
 -15945 20650 17032 13700 -4864 2374]
[ -2116 24013 6009 2720 22595 4548 -31684 1184 -9192 -4131
  27806 25601 -31968 6013 1760 82]
[-26944 -29198 -32622 0]
wizard:plymgen graham$

"""

Learn about this subject
This module and example are covered on the following public courses:
 * Learning to program in Python
 * Python Programming
Also available on on site courses for larger groups

Books covering this topic
Yes. We have over 700 books in our library. Books covering Python are listed here and when you've selected a relevant book we'll link you on to Amazon to order.

Other Examples
This example comes from our "numpy, scipy and matplotlib" training module. You'll find a description of the topic and some other closely related examples on the "numpy, scipy and matplotlib" module index page.

Full description of the source code
You can learn more about this example on the training courses listed on this page, on which you'll be given a full set of training notes.

Many other training modules are available for download (for limited use) from our download centre under an Open Training Notes License.

Other resources
• Our Solutions centre provides a number of longer technical articles.
• Our Opentalk forum archive provides a question and answer centre.
The Horse's mouth provides a daily tip or thought.
• Further resources are available via the resources centre.
• All of these resources can be searched through through our search engine
• And there's a global index here.

Purpose of this website
This is a sample program, class demonstration or answer from a training course. It's main purpose is to provide an after-course service to customers who have attended our public private or on site courses, but the examples are made generally available under conditions described below.

Web site author
This web site is written and maintained by Well House Consultants.

Conditions of use
Past attendees on our training courses are welcome to use individual examples in the course of their programming, but must check the examples they use to ensure that they are suitable for their job. Remember that some of our examples show you how not to do things - check in your notes. Well House Consultants take no responsibility for the suitability of these example programs to customer's needs.

This program is copyright Well House Consultants Ltd. You are forbidden from using it for running your own training courses without our prior written permission. See our page on courseware provision for more details.

Any of our images within this code may NOT be reused on a public URL without our prior permission. For Bona Fide personal use, we will often grant you permission provided that you provide a link back. Commercial use on a website will incur a license fee for each image used - details on request.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/ex.php • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb