Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 20,946
» Latest member: blackopsdlc
» Forum threads: 22,001
» Forum posts: 22,968

Full Statistics

Online Users
There are currently 1348 online users.
» 0 Member(s) | 1342 Guest(s)
Applebot, Baidu, Bing, Facebook, Google, Yandex

Latest Threads
How to unlock Maya Aguina...
Forum: PC Discussion
Last Post: xSicKxBot

» Replies: 0
» Views: 0
[Steam Release] The Unive...
Forum: New Game Releases
Last Post: xSicKxBot

» Replies: 0
» Views: 10
[DevBlog MS] Creating a m...
Forum: C#, Visual Basic, & .Net Frameworks
Last Post: xSicKxBot

» Replies: 0
» Views: 10
[WoW Retail News] Fixed C...
Forum: World of Warcraft
Last Post: xSicKxBot

» Replies: 0
» Views: 12
[PS.Blog] Fading Echo mak...
Forum: Sony Discussion
Last Post: xSicKxBot

» Replies: 0
» Views: 12
[Steam Release] Cowbots a...
Forum: New Game Releases
Last Post: xSicKxBot

» Replies: 0
» Views: 16
[Dev News] September Free...
Forum: Game Development
Last Post: xSicKxBot

» Replies: 0
» Views: 13
Marvel Rivals Venom guide...
Forum: PC Discussion
Last Post: xSicKxBot

» Replies: 0
» Views: 18
[WoW Retail News] Midnigh...
Forum: World of Warcraft
Last Post: xSicKxBot

» Replies: 0
» Views: 23
[Steam Release] Kodon
Forum: New Game Releases
Last Post: xSicKxBot

» Replies: 0
» Views: 22

 
  [Tut] JavaScript localStorage – Simple Guide with Example
Posted by: xSicKxBot - 08-21-2022, 08:08 PM - Forum: PHP Development - No Replies

JavaScript localStorage – Simple Guide with Example

by Vincy. Last modified on August 21st, 2022.

This article is for learning how to use JavaScript localStorage to put a string or object into it. This is for storing data in the client browser and use it when the need arises.

Data storage is a critical part of programming. These are the scenarios the localStorage used for adding persistency on the client-side.

  1. To store the session and the unique identity of a guest user to manage the state of his selection.
  2. To store shopping cart selected items on the client-side.
  3. To store language preferences to display content on a multilingual site.
  4. To store user preferences to display data, time and timezone as selected on the client.

Let us see a quick example of using the JavaScript localStorage to store an object. It prepares a JSON object of an array of data and put it into the localStorage.

Quick example


var animalObject = { 'Lion': 'Wild', 'Dog': 'Domestic'
}; // flatten the animal object as a string
animalString = JSON.stringify(animalObject); //store the string into local storage
localStorage.setItem('animals', animalString);

Quick example output


Log this localStorage object into the developer’s browser console to display the following output.

Object from local storage: {Lion: 'Wild', Dog: 'Domestic'}

In a previous tutorial, we used JavaScript localStorage to create a persistent shopping cart.

javascript localstorage howto store object


What is localStorage?


The JavaScript localStorage is the global window object property. It is used to store the data to carry over page-to-page.

It is one of the storage mechanisms coming under the Web Storage API.

It can not replace the server-side solutions providing persistency. But, it is a good mechanism for non-dynamic websites.

It contains a handle to access the local storage space of the browser origin.

Properties


Web Storage API


Web Storage API provides two concepts to store the objects having data in a key: value format.

  1. window.localStorage
  2. window.sessionStorage

Both use different Storage instances and control the actions separately.

This storage object is similar to the JavaScript localStorage. But, it has an expiration time.

It is valid only on the current browser session. When closing and reloading the browser, then the sessionStorage object is elapsed.

The expiration time is the main difference between these two storage concepts.

How to set and get items in JavaScript localStorage?


This example is for learning a basic usage of the JavaScript localStorage object. It performs the following actions on the localStorage about a String item.

  1. To set an item as a key-value pair.
  2. To get the value of an item by key.
  3. To remove an item by key.
  4. To clear the entire localStorage.
  5. To get the key by item index position.

This localStorage class contains functions used to perform the above actions. This program uses these functions with appropriate parameters.

basics.html

<html>
<head>
<title>JavaScript localStorage Example and how to store a JavaScript object</title>
</head>
<body> <script> // set item in localstorage window.localStorage.setItem('king', 'Lion'); console.log("Local Storage Key-Value = " + JSON.stringify(window.localStorage) + "\n"); // get item from JavaScript localStorage window.localStorage.getItem('king'); console.log("Local Storage Value = " + window.localStorage.getItem('king') + "\n"); // to get name of key using index var indexPosition = parseInt(window.localStorage.length) -1; var KeyName = window.localStorage.key(indexPosition); console.log("Local Storage Key = " + KeyName + "\n"); // remove item from JavaScript localStorage window.localStorage.removeItem('king'); // to clear all items from localStorage window.localStorage.clear(); </script>
</body>
</html>

Output

The above program displays the following output. It is for printing the localStorage data, it’s key and value based on the appropriate function calls.

Local Storage Key-Value = {"king":"Lion"} Local Storage Value = Lion Local Storage Key = king

Store JavaScript object in HTML5 browser localStorage


This example is to store an object in the JavaScript localStorage. It proceeds with the following steps to achieve this.

  1. It builds a JSON object to have a property array.
  2. It converts the object into a string using JSON stringify.
  3. Then put the JSON string into the localStorage.

Like the above basic example, it calls the getItem() by object key to get the property mapping.

The retrieved string output from the localStorage is converted back to an object. The example outputs the converted object to the browser console.

index.html

<html>
<head>
<title>JavaScript localStorage Example and how to store a JavaScript object</title>
</head>
<body> <h1>JavaScript localStorage Example and how to store a JavaScript object</h1> <script> // Example: Store JavaScript object in HTML5 browser localStorage var animalObject = { 'Lion' : 'Wild', 'Dog' : 'Domestic', 'Tiger' : 'Wild' }; // flatten the object as a string animalString = JSON.stringify(animalObject); //store the string into local storage localStorage.setItem('animals', animalString); //retrieve the string from local storage var retrievedString = localStorage.getItem('animals'); // parse the string back to an object convertedObject = JSON.parse(retrievedString); console.log('Object from local storage: ', convertedObject); </script>
</body>
</html>

Output


Object from local storage: {Lion: 'Wild', Dog: 'Domestic', Tiger: 'Wild'}

We learned how to use JavaScript localStorage to set a String or an Object and use it later when needed.

↑ Back to Top



https://www.sickgaming.net/blog/2022/08/...h-example/

Print this item

  (Indie Deal) PMCW Intelligence Document No. 010178. Codename: Vorax
Posted by: xSicKxBot - 08-21-2022, 08:08 PM - Forum: Deals or Specials - No Replies

PMCW Intelligence Document No. 010178. Codename: Vorax

PMCW Intelligence Document No. 010178.

Information in our possession is conflicting, but it seems that the infection has spread very quickly within a few days, perhaps even in a few hours.
It seems that in the hours immediately following the outbreak of the infection, 43rd NATO airborne battalion was sent to the island but all contacts were lost after only 8 hours.

PMCW considers this matter with the utmost importance.
Objectives of team W1 are:

  • Locate the biolab
  • Take in vitro samples of the pathogen (codename: "Vorax")
  • Liquidate surviving medical personnel (optionally) and any witnesses.
In NO case must the presence of the PMCW be revealed.

Every W1 squad member is equipped with cyanide capsules.
Squad commander is authorized to start liquidation procedure in case of emergency.

Proceed with the utmost caution.



THE ENVIRONMENT

The island is vast and offers a wide variety of natural resources. There are also several settlements, a main village, a hotel and tourist attractions.
In the event of an emergency landing, or loss of tactical equipment, each squad member is trained to survive in a hostile environment.
As a good mercenary of a private military company, you know how to use local plants and herbs to make ointments and medications to treat state effects such as burns, bleeding, relieve your stress or simply restore your health.
But more importantly, you can use building materials provided by nature to make rudimentary melee weapons, traps, barricades and much more. Even a silent bow, very useful for knocking out the infected without being detected.

THE INFECTION

It seems that the infected are the side effect of the virus grown in the bio-laboratory.
Probably when a security flaw opened, the virus spread to the island.

It is not yet clear whether it spreads by air or through aquifers but what is certain is that biomass, similar to fleshy appendages that are sometimes glimpsed in the environment, are one of the final stages of the virus.
The biomass therefore seems to be responsible for the mutations that occurred to the civilian inhabitants and to the military personnel who rushed to contain the first stages of the infection.
Contact with non-bottled liquids or non-canned food is therefore strictly prohibited.

Mutates are fast, extremely aggressive and above all voracious.
The first to be devoured were the breeding animals of the surrounding farms and estates.
For this reason, any living being, human or animal, is for them a prey.

Apparently they do not devour each other ( to be confirmed ).

Finally, it seems that they are photosensitive.
At least the infected humans.
Our drones have in fact observed the absence of external diurnal activity by the mutants, even if some animal species that have come into contact with the pathogen, such as stray dogs, wolves, wild boars and bears, do not seem to suffer from photosensitivity.

It is therefore recommended to exercise extreme caution at night.


OPERATIONAL INFO

You will land in the North area, a few hundred meters from the bio-laboratory, at 4.30 in the morning.
The helicopter will wait 25 minutes and then will take off.

https://store.steampowered.com/app/1874190/Vorax





https://steamcommunity.com/groups/indieg...4769029421

Print this item

  News - Jetpack Joyride 2 Is Out Today Exclusively On Apple Arcade
Posted by: xSicKxBot - 08-21-2022, 08:08 PM - Forum: Lounge - No Replies

Jetpack Joyride 2 Is Out Today Exclusively On Apple Arcade

Halfbrick Studios, the developer behind the highly successful Fruit Ninja, released the original Jetpack Joyride in 2011, and today, more than a decade later, Jetpack Joyride 2 is finally available exclusively on Apple Arcade.

The original game, which continues to receive updates, is a free-to-play endless runner, but for the sequel, the team opted for an experience with a full campaign featuring levels and bosses. You can also upgrade all of protagonist Barry Steakfries' weapons and jetpack, and since the game is on Apple Arcade, you won't encounter any in-game monetization.

One thing the game is missing, surprisingly, is an endless mode. We spoke with Jetpack Joyride 2 lead game designer Francisco Gonzalez and lead artist Toni Martin about the game's development earlier this month and they said that mode is on the way. “Endless mode is something we know for sure some of the fans will ask for and it is something we are preparing," Gonzalez says. "Of course, our intention is to maintain the game over the next months. We will issue updates and this will be one of the updates we add soon.”

Continue Reading at GameSpot

https://www.gamespot.com/articles/jetpac...01-10abi2f

Print this item

  PC - Arcade Paradise
Posted by: xSicKxBot - 08-21-2022, 08:08 PM - Forum: New Game Releases - No Replies

Arcade Paradise



Welcome to Arcade Paradise, the 90's-fuelled retro arcade adventure. Rather than washing rags for a living, you decide to turn the family laundromat into the ultimate arcade. Play, profit and purchase new arcade machines, with over 35 to choose from, to build your very own Arcade Paradise!

Take the laundromat business made up of dull chores from washing clothes to throwing out the trash, and turn it into a booming arcade with the coolest games in town raking in all the money!

Over 35 arcade games, each fully realized with its own gameplay, stories, missions and high scores to set! Inspired by 3 decades of gaming, from early vector games right up to the 32-bit era.

Insert a second coin and play against a friend in a number of co-operative & competitive arcade games up to 4 players locally.

Publisher: Wired Productions

Release Date: Aug 11, 2022




https://www.metacritic.com/game/pc/arcade-paradise

Print this item

  [Tut] Python Convert GeoJSON to CSV
Posted by: xSicKxBot - 08-20-2022, 10:07 PM - Forum: Python - No Replies

Python Convert GeoJSON to CSV

5/5 – (1 vote)

What is GeoJSON?


? GeoJSON is an RFC standardized data format to encode geographic data structures such as Point, LineString, Polygon, MultiPoint, MultiLineString, and MultiPolygon. GeoJSON is based on the JavaScript Object Notation (JSON).

Example GeoJSON to CSV


Say, you have the following GeoJSON snippet:

{ "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-75.343, 39.984]}, "properties": { "name": "Location A", "category": "Store" } }, { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-80.24, 40.12]}, "properties": { "name": "Location B", "category": "House" } }, { "type": "Feature", "geometry": {"type": "Point", "coordinates": [ -77.2, 41.427]}, "properties": { "name": "Location C", "category": "Office" } } ] }

You want to convert it to the following CSV format:

latitude,longitude,altitude,geometry,name,category
39.984,-75.343,,Point,Location A,Store
40.12,-80.24,,Point,Location B,House
41.427,-77.2,,Point,Location C,Office

Python GeoJSON to CSV Conversion


The Python code to convert a GeoJSON to a CSV in Python uses a combination of the json and csv packages.

import json
import csv geo_filename = 'my_file.json'
csv_filename = 'my_file.csv' def feature_to_row(feature, header): l = [] for k in header: l.append(feature['properties'][k]) coords = feature['geometry']['coordinates'] assert(len(coords)==2) l.extend(coords) return l with open(geo_filename, 'r') as geo_file: with open(csv_filename, 'w', newline='') as csv_file: geojson_data = json.load(geo_file) features = geojson_data['features'] csv_writer = csv.writer(csv_file) is_header = True header = [] for feature in features: if is_header: is_header = False header = list(feature['properties'].keys()) header.extend(['px','py']) csv_writer.writerow(header) csv_writer.writerow(feature_to_row(feature, feature['properties'].keys()))

You can either copy&paste this code and run it in the same folder as your GeoJSON (of course, after renaming the input and output filenames.

Or you can check out this excellent GitHub to get a more “scriptable” variant to be used in the command line. This code is inspired by the GitHub but simplified significantly.

Example input:

{ "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-75.343, 39.984]}, "properties": { "name": "Location A", "category": "Store" } }, { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-80.24, 40.12]}, "properties": { "name": "Location B", "category": "House" } }, { "type": "Feature", "geometry": {"type": "Point", "coordinates": [ -77.2, 41.427]}, "properties": { "name": "Location C", "category": "Office" } } ] }

Example output:


GeoJSON to CSV in QGIS


In QGIS, if you have a map like this one (source):


You can convert GEOJSON to CSV right within QGIS by clicking Export, then Save Feature As and select the Comma Separated Value [CSV] selector in the first dropdown menu.

enter image description here
(source)

enter image description here
(source)

GeoJSON to CSV Online Converter


You can easily convert specific GeoJSON snippets to CSV using the following online converter:




https://www.sickgaming.net/blog/2022/08/...on-to-csv/

Print this item

  News - How To Do A QB Slide In Madden 23
Posted by: xSicKxBot - 08-20-2022, 10:07 PM - Forum: Lounge - No Replies

How To Do A QB Slide In Madden 23

Madden 23 is now out for the entire community and every fan is diving into another year of virtual football. While a majority of the player base are returning veterans, there is a solid chunk of players that haven't played a Madden game before or are coming back after a lengthy hiatus. If you're in this camp or simply don't remember some controls, then you're going to need a crash course on how to perform some of the most basic, yet important, mechanics in Madden 23. One such mechanic that every player needs to know how to do is a QB slide.

The quarterback is the most important player on the field at any given time, and it's vital that players know the best ways to protect them. While a quarterback's job is usually to throw the ball to a receiver, sometimes a play doesn't work out that way, and you need to escape the pocket with the QB. Or, you could be playing as a team with a speedy quarterback, such as Lamar Jackson or Kyler Murray, and use QB run plays as a part of your offense. Either way, in order to maximize your potential with a mobile QB and ensure they don't get injured or fumble the ball, you need to know how to QB slide in Madden 23.

Doing a QB Slide

Fortunately, the controls for sliding with your quarterback are the same for any other ball carrier. However, there are some pitfalls to avoid when attempting to slide that players need to be aware of in Madden 23.

Continue Reading at GameSpot

https://www.gamespot.com/articles/how-to...01-10abi2f

Print this item

  (Indie Deal) FREE Larry 5, VR Hope Bundle, Mega Man Deal
Posted by: xSicKxBot - 08-20-2022, 10:07 PM - Forum: Deals or Specials - No Replies

FREE Larry 5, VR Hope Bundle, Mega Man Deal

Leisure Suit Larry 5 - Passionate Patti Does a Little Undercover Work
[freebies.indiegala.com]
Passionate Patti Does a Little Undercover Work! is (despite the number) the fourth game in Al Lowe's Leisure Suit Larry series.

VR Hope Bundle | 6 VR Steam Games | 93% OFF
[www.indiegala.com]
Where's hope, there's life...virtual life. Enter a whole new reality with a whole new VR bundle including: The Great C, HOPE VR: Progressive Meditation, Dark Threads, VR Walking Simulator, Legendary Hunter VR & Dodo Adventures.

Deal Ending Soon: The Quarry[www.indiegala.com]
https://www.youtube.com/watch?v=Zh2K7SxRHmo
Mega Man Deal & more Sales
[www.indiegala.com]

https://www.youtube.com/watch?v=JtJ_8Aj52co
Stay Inside, Stay Safe and Enjoy Good Games.
Check out IndieGala on Twitter, YouTube & Facebook[www.facebook.com]


https://steamcommunity.com/groups/indieg...0805054150

Print this item

  PC - Lost in Play
Posted by: xSicKxBot - 08-20-2022, 10:07 PM - Forum: New Game Releases - No Replies

Lost in Play



Go on a feel-good adventure with a brother and sister as they explore dreamscapes and befriend magical creatures. Lost in their imagination, Toto and Gal must stick together and solve puzzles to journey back home. This whimsical puzzle adventure game will make you feel like you're playing a cartoon!

Publisher: HappyJuice Games

Release Date: Aug 10, 2022




https://www.metacritic.com/game/pc/lost-in-play

Print this item

  [Oracle Blog] JDK 16.0.1, 11.0.11, 8u291, and 7u301 Have Been Released!
Posted by: xSicKxBot - 08-19-2022, 06:55 PM - Forum: Java Language, JVM, and the JRE - No Replies

JDK 16.0.1, 11.0.11, 8u291, and 7u301 Have Been Released!

The Java SE 16.0.1, 11.0.11, 8u291, and 7u301 update releases are now available. You can download the latest JDK releases from the Java SE Downloads page. OpenJDK 16.0.1 is available on http://jdk.java.net/16/. New Features, Changes, and Notable Bug Fixes For information about the new features, chan...

https://blogs.oracle.com/java/post/jdk-1...n-released

Print this item

  [Tut] How to Iterate over a NumPy Array
Posted by: xSicKxBot - 08-19-2022, 06:55 PM - Forum: Python - No Replies

How to Iterate over a NumPy Array

Rate this post

Problem Formulation and Solution Overview


In this article, you’ll learn how to iterate over a 1D, 2D and 3D NumPy array using Python.

When working with the NumPy library, you will encounter situations where you will need to iterate through a 1D, 2D and even a 3D array. This article will show you how to accomplish this task.


? Question: How would we write code to iterate through a 1D, 2D or 3D NumPy array?

We can accomplish this task by one of the following options:


Preparation


Before moving forward, please ensure the NumPy library is installed. Click here if you require instructions.

Then, add the following code to the top of each script. This snippet will allow the code in this article to run error-free.

import numpy as np 

After importing the NumPy library, this library is referenced by calling the shortcode (np).


Method 1: Use a For Loop and np.array()


This method uses a For loop combined with np.array() to iterate through a 1D NumPy array. The first five (5) Atomic Numbers from the Periodic Table are generated and displayed for this example.

atomic_els = np.array(np.arange(1,6)) for el in atomic_els: print(el, end=' ')

Above, calls the np.array() function and passes it np.arange(1,6) with two (2) arguments: a start position of one (1) and stop position of five (5) or (stop-1). The result is an array of integers and saves to atomic_els.


[1 2 3 4 5]

Next, a For loop is instantiated and iterates through each element of the 1D NumPy array atomic_els.

The output is sent to the terminal on one (1) line as an additional argument was passed to the print statement (end=' '). This argument replaces the default newline character with a blank space.


1 2 3 4 5

YouTube Video


Method 2: Uses a For Loop and nditer()


This method uses a for loop combined with np.nditer() to iterate through a NumPy array. The first five (5) Atomic Numbers and Number of Neutrons data from the Periodic Table display for this example.

atomic_data = np.array([np.arange(1,6), [0, 2, 4, 5, 6]]) for dim in atomic_data: for d in dim: print(d, end=' ')

Above, calls the np.array() function and passes np.arange(1,6) as the first argument and an array of associated Number of Neutrons values as the second.

Next, an outer for loop is instantiated. This iterates through each array dimension.

Inside this loop, another for loop is instantiated. The inside loop iterates through each element of the above dimensions.

The output is sent to the terminal on one (1) line as an additional argument is passed to the print statement (end=' '). This argument replaces the default newline character with a blank space.


1 2 3 4 5 0 2 4 5 6

?Note: The first dimension is highlighted to easily differentiate the dimensions.

YouTube Video


Method 3: Use a For Loop and itertools


This method uses a for loop and Python’s built-in itertools library to iterate through a NumPy array. The first three (3) Atomic Numbers, Phase, and Group data from the Periodic Table display for this example.

import itertools atomic_num = np.arange(1,4)
atomic_phase = ['gas', 'gas', 'solid']
atomic_group = [1, 18, 1] for (a, b, c) in itertools.zip_longest(atomic_num, atomic_phase, atomic_group, fillvalue=0): print (a, b, c)

Above, imports the itertools library to use the zip_longest() function.

Then, three (3) arrays are declared containing the relevant data for the first three (3) elements from the Periodic Table. They save respectively to atomic_num, atomic_phase, and atomic_group.

Next, a for loop is instantiated and passed three (3) arguments inside the brackets (a, b, c) which reference the arguments inside the zip_longest(atomic_num, atomic_phase, atomic_group) function.

An additional argument (fillvalue=0) is also passed. This fills in any missing values for lists of unequal lengths with the stated value.

The loop iterates until the end of the arrays are reached, outputting to the terminal for each iteration.


1 gas 1
2 gas 18
3 solid 1

YouTube Video


Method 4: Use a While Loop and Size


This method uses a while loop combined with np.size to iterate through a NumPy array. The first five (5) Atomic Numbers, Number of Neutrons, and Phase data from the Periodic Table display for this example.

atomic_names = np.array(['Hydrogen', 'Helium', 'Lithium', 'Beryllium', 'Boron'])
el_count = 0 while el_count < atomic_names.size: print(atomic_names[el_count], end=' ') el_count += 1

Above, calls the np.array() function and passes a list containing the first five (5) element names of the Periodic Table. These results save to atomic_names.

Then, a variable, el_count, is declared with a start value of zero (0). This will be a counter variable and lets the While loop know when to stop iterating.

Next, a while loop is instantiated and iterates through the elements of atomic_names. This will continue while the value of el_count remains less than the value of atomic_names.size.

The output is sent to the terminal on one (1) line as an additional argument is passed to the print statement (end=' '). This argument replaces the default newline character with a blank space.


Hydrogen Helium Lithium Beryllium Boron


Method 5: Use a For Loop and np.ndenumerate()


This method uses a For loop and np.ndenumerate() to iterate through a NumPy array. The first five (5) Element Names from the Periodic Table display for this example.

atomic_names = np.array(['Hydrogen', 'Helium', 'Lithium', 'Beryllium', 'Boron']) for idx, x in np.ndenumerate(atomic_names): print(idx, x)

Above, calls the np.array() function and passes it an array containing the first five (5) element names from the Periodic Table. The results save to atomic_names.

Next, a for loop is instantiated referencing idx which is the index of the array, and x, which is the array element’s value.

The output is sent to the terminal. Then idx displays a Tuple containing the index value of the array and then the value of x for each iteration.


(0,) Hydrogen
(1,) Helium
(2,) Lithium
(3,) Beryllium
(4,) Boron


Method 6: Use a For Loop and range()


This method uses a for loop and range()) to iterate through a 3D NumPy array.

nums = np.array([[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]], [[13, 14], [15, 16], [17, 18]], [[19, 20], [21, 22], [23, 23]], [[24, 25], [26, 27], [28, 29]]]) for x in range(0, 5): for y in range(0, 3): for z in range(0, 2): print(nums[x][y][z])

Above declares a 3D NumPy array containing consecutive numbers from 1-29 inclusive. These save to nums.

Next, three (3) for loops are instantiated to loop through and output the contents of nums to the terminal one (1) number per line.

The range() function for each loop is based on the dimensions of the 3D Numpy array, for example:

  • The first loop (range(0,5) identifies the total number of tows in the array.

  • The next loop (range(0,3) identifies the number of columns in the array.

  • The final loop (range(0,2) identifies the elements in each column in the array.

Finally, the output is sent to the terminal (snippet only).


1
2
3
4
5
6
7
8
9
10
...


Bonus: Convert CSV to np.array()


This example reads in a snippet of the Periodic Table as a CSV file. This data is converted to a NumPy array and is output to the terminal.

The CSV file below contains the values of the Atomic Number, Atomic Mass, Number of Neutrons, and the Number of Electrons for the first seven (7) elements from the Periodic Table.

Contents of pt_sample.csv


1,1.007,0
2,4.002,2
3,6.941,4
4,9.012,5
5,10.811,6
6,12.011,6
7,14.007,7

To follow along, save this file as pt_sample.csv and move it into the current working directory.

Before moving forward, please ensure the Pandas library is installed. Click here if you require instructions.

import pandas as pd
import csv file_name = 'pt_sample.csv'
df_data = np.array(list(csv.reader(open(file_name, 'r'), delimiter=','))).astype("float")
print(df_data)

Above, imports the Pandas library and the CSV library. This is needed to work with DataFrames and read in the CSV file.

Then, a filename is declared and saves to file_name.

On the highlighted line, the np.array() function is called and passed the following arguments.

  • The csv.reader() function is passed as an argument and this argument passes the open() method to open the specified CSV file in read (r) mode, including the field delimiter (csv.reader(open(file_name, 'r'), delimiter=',')).
  • The contents of the CSV file converts to a list.
  • This list converts to an np.array().

The results save to df_data and output to the terminal.


[[ 1. 1.007 0. ]
[ 2. 4.002 2. ]
[ 3. 6.941 4. ]
[ 4. 9.012 5. ]
[ 5. 10.811 6. ]
[ 6. 12.011 6. ]
[ 7. 14.007 7. ]]

YouTube Video


Summary


These seven (7) methods of iterating a NumPy array should give you enough information to select the best one for your coding requirements.

Good Luck & Happy Coding!


Programmer Humor – Blockchain


“Blockchains are like grappling hooks, in that it’s extremely cool when you encounter a problem for which they’re the right solution, but it happens way too rarely in real life.” source xkcd



https://www.sickgaming.net/blog/2022/08/...mpy-array/

Print this item